新手:c#中oledb提交SQL语句问题请指点

faust 2012-05-23 09:51:35
using System;
using System.Data;
using System.Data.OleDb;
namespace test{
class Program
{
static void Main(string[] args)
{

OleDbConnection con = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter dapter = new OleDbDataAdapter();
String conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= D:\\1.mdb";
con.ConnectionString = conStr;
con.Open();
cmd.Connection = con;
String SQLStr = "if object_id(N'detectingCannalId') is Null create table detectingCannalId(detectingNo varchar(20) not null,cannalId int not null,checked bit not null default 0 )";
cmd.CommandText = SQLStr;
cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();
}
}
}

SQLStr = "if object_id(N'detectingCannalId') is Null create table detectingCannalId(detectingNo varchar(20) not null,cannalId int not null,checked bit not null default 0 )";
不可执行
SQLStr = "create table detectingCannalId(detectingNo varchar(20) not null,cannalId int not null,checked bit not null default 0 )";
可执行

该如何做给可行代码,拒绝无完整且正确语句的概念介绍。
...全文
168 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dalmeeme 2012-05-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

请问楼上有什么SQL语句能对ACCESS执行判断有无表,无表就新建的??
[/Quote]
http://wenku.baidu.com/view/8c75bcddd15abe23482f4dff.html#
test2050 2012-05-23
  • 打赏
  • 举报
回复
能不能用自己网上找代码动手测试,断点调试下。不要等别人给你完整且正确的语句
faust 2012-05-23
  • 打赏
  • 举报
回复
Public function tableExists(findTable as string) as boolean
Dim rstSchema As New ADODB.Recordset
Set rstSchema = cn.OpenSchema(adSchemaTables)
rstSchema.Find "TABLE_NAME= '" & findTable &"'"
If rstSchema.EOF Then
TableExists= False
Else
TableExists = True
End If
rstSchema.Close
End Function

好像大家推荐以上方式处理OLEDB
这代码对ACCESS,SQLSERVER,ORACEL都能用么??
faust 2012-05-23
  • 打赏
  • 举报
回复
请问楼上有什么SQL语句能对ACCESS执行判断有无表,无表就新建的??
bdmh 2012-05-23
  • 打赏
  • 举报
回复
object_id这是sqlserver的,不是access的
faust 2012-05-23
  • 打赏
  • 举报
回复
这个是用ADOX的。谢谢大家。

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧