Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C#2013将SQL插入语法错误 string Connstr=(@“Provider=Microsoft.ACE.OLEDB.12.0;数据源=C:\Users\Shahrivar92\Documents\Safa_co.accdb”); OLEDB连接分子n=新的OLEDB连接(Connstr); OLEDBCOMAND olecmd=新的OLEDBCOMAND(); olecmd.Connection=oleconn; olecmd.CommandText=string.Format(“插入信息ghrardad(gh note,gh tarikh,gh mablagh,gh shomareh,gh modat,今日日期)值(@gh note,@gh tarikh,@gh mablagh,@gh shomareh,@gh modat,今日日期)”; 尺骨鹰嘴开(); olcemd.Parameters.AddWithValue(“@gh note”,gh_name.Text); olcemd.Parameters.AddWithValue(“@gh-tarikh”,gh_-date.Text); olecmd.Parameters.AddWithValue(“@gh-mablagh”,gh_-mablagh.Text); olcemd.Parameters.AddWithValue(“@gh shomareh”,gh_number.Text); olecmd.Parameters.AddWithValue(“@gh modat”,gh_modat.Text); olecmd.Parameters.AddWithValue(“@today date”,TodayDate.Text); oclemd.ExecuteNonQuery(); 鹰嘴闭合();_C#_Sql_Visual Studio_Visual Studio 2013_Ms Access 2010 - Fatal编程技术网

使用C#2013将SQL插入语法错误 string Connstr=(@“Provider=Microsoft.ACE.OLEDB.12.0;数据源=C:\Users\Shahrivar92\Documents\Safa_co.accdb”); OLEDB连接分子n=新的OLEDB连接(Connstr); OLEDBCOMAND olecmd=新的OLEDBCOMAND(); olecmd.Connection=oleconn; olecmd.CommandText=string.Format(“插入信息ghrardad(gh note,gh tarikh,gh mablagh,gh shomareh,gh modat,今日日期)值(@gh note,@gh tarikh,@gh mablagh,@gh shomareh,@gh modat,今日日期)”; 尺骨鹰嘴开(); olcemd.Parameters.AddWithValue(“@gh note”,gh_name.Text); olcemd.Parameters.AddWithValue(“@gh-tarikh”,gh_-date.Text); olecmd.Parameters.AddWithValue(“@gh-mablagh”,gh_-mablagh.Text); olcemd.Parameters.AddWithValue(“@gh shomareh”,gh_number.Text); olecmd.Parameters.AddWithValue(“@gh modat”,gh_modat.Text); olecmd.Parameters.AddWithValue(“@today date”,TodayDate.Text); oclemd.ExecuteNonQuery(); 鹰嘴闭合();

使用C#2013将SQL插入语法错误 string Connstr=(@“Provider=Microsoft.ACE.OLEDB.12.0;数据源=C:\Users\Shahrivar92\Documents\Safa_co.accdb”); OLEDB连接分子n=新的OLEDB连接(Connstr); OLEDBCOMAND olecmd=新的OLEDBCOMAND(); olecmd.Connection=oleconn; olecmd.CommandText=string.Format(“插入信息ghrardad(gh note,gh tarikh,gh mablagh,gh shomareh,gh modat,今日日期)值(@gh note,@gh tarikh,@gh mablagh,@gh shomareh,@gh modat,今日日期)”; 尺骨鹰嘴开(); olcemd.Parameters.AddWithValue(“@gh note”,gh_name.Text); olcemd.Parameters.AddWithValue(“@gh-tarikh”,gh_-date.Text); olecmd.Parameters.AddWithValue(“@gh-mablagh”,gh_-mablagh.Text); olcemd.Parameters.AddWithValue(“@gh shomareh”,gh_number.Text); olecmd.Parameters.AddWithValue(“@gh modat”,gh_modat.Text); olecmd.Parameters.AddWithValue(“@today date”,TodayDate.Text); oclemd.ExecuteNonQuery(); 鹰嘴闭合();,c#,sql,visual-studio,visual-studio-2013,ms-access-2010,C#,Sql,Visual Studio,Visual Studio 2013,Ms Access 2010,除了marc_关于命名参数的评论和使用“?”作为占位符外,表a的列名使用“-”作为名称是一种非常糟糕的命名约定。这就像你告诉系统减去两个值 也就是说,您可能需要将insert值更改为“?”占位符,并按相同的顺序添加它们(您已经有了),但也可能需要将列名括在括号内、勾号内,等等,例如 insert into [info-ghrardad] ( [gh-note], [gh-tarikh], [gh-mablagh], [gh-shomareh], [gh-modat], [today-dat

除了marc_关于命名参数的评论和使用“?”作为占位符外,表a的列名使用“-”作为名称是一种非常糟糕的命名约定。这就像你告诉系统减去两个值

也就是说,您可能需要将insert值更改为“?”占位符,并按相同的顺序添加它们(您已经有了),但也可能需要将列名括在括号内、勾号内,等等,例如

insert into [info-ghrardad] (
   [gh-note], [gh-tarikh], [gh-mablagh], [gh-shomareh], [gh-modat], [today-date] )
   values( ?, ?, ?, ?, ?, ?)");
然后你的参数


此外,如果只是将日期字段作为文本输入,而不是实际的日期或日期/时间数据类型值(如果实际结构是这样的话),则日期字段可能是崩溃的一部分。类似地,如果金额应该是数字,并且您正在抓取简单文本,请确保它的列格式正确。

OleDB不支持命名参数,据我所知-您只需要在SQL语句中使用
作为占位符,您可以为参数名使用几乎任何名称-这只取决于参数的位置(添加的第一个参数与第一个问号匹配,第二个参数与第二个问号匹配,依此类推)。是的,表名和字段名必须包含在方括号中,因为它们包含连字符(“减号”)。建议将
@parameterName
转换为
占位符,但并非绝对必需,前提是参数是按照其占位符在命令文本中的显示顺序定义的。
insert into [info-ghrardad] (
   [gh-note], [gh-tarikh], [gh-mablagh], [gh-shomareh], [gh-modat], [today-date] )
   values( ?, ?, ?, ?, ?, ?)");