类似{&'不正确的语法'Name'附近的错误。"}即将发生。 [英] Error like {"Incorrect syntax near 'Name'."} is coming.
本文介绍了类似{&'不正确的语法'Name'附近的错误。"}即将发生。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我得到错误{'Name'附近的语法不正确。}使用以下代码:
Hi i m getting error {"Incorrect syntax near 'Name'."} with the following code:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=FSPL-DSKTP-034;Initial Catalog=FSPL_AMC;Integrated Security=True");
con.Open();
using (SqlCommand command = new SqlCommand("Insert into VanderDetail(Vandor Name, Asset Type, Status, Date of registration, Phone Number, Email) values(@Vandor Name, @Asset Type,@ Status, @Date of registration,@Phone Number,@Email)", con))
{// 2. define parameters used in command object
SqlParameter param = new SqlParameter();
param.ParameterName = "@Vandor Name"; param.Value = TextBox1.Text.Trim();
param.ParameterName = "@Asset Type"; param.Value = TextBox2.Text.Trim();
param.ParameterName = "@Status"; param.Value = TextBox3.Text.Trim();
param.ParameterName = "@Date of registration"; param.Value = TextBox6.Text.Trim();
param.ParameterName = "@Phone Number"; param.Value = TextBox4.Text.Trim();
// 3. add new parameter to command object
param.ParameterName = "@Email"; param.Value = TextBox5.Text.Trim(); command.Parameters.Add(param); // // Read in the SELECT results. //
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
//string com = "insert into VandorDetail(Vandor Name,Asset Type,Status, Date of registration, Phone Number,Email) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox6.Text + "'" + TextBox4.Text + "'" + TextBox5.Text + "'";
//SqlCommand comm = new SqlCommand(com, con);
//comm.ExecuteNonQuery();
Populategridview();
}
}
推荐答案
如果您的字段名称包含空格,则应使用下一种方式:[Vandor Name],[注册日期]等。
If your fields names contains space you should used in the next way: [Vandor Name], [Date of registration], etc.
你必须删除两个字段之间的空格并按照这些方法中的任何一个
you have to remove space in between of fields and follow any one of these methodology
Vandor Name
你应该写
VandorName
或使用
or use
Vandor_Name
或
or
[Vandor_Name]
以下行中的Insert语句语法错误:
The Insert statement syntax is wrong in the line below:
using (SqlCommand command = new SqlCommand("Insert into VanderDetail(Vandor Name, Asset Type, Status, Date of registration, Phone Number, Email) values(@Vandor Name, @Asset Type,@ Status, @Date of registration,@Phone Number,@Email)", con))
列名不能多措辞,如果是,则需要在方括号内。您的情况下的参数也不能有空格。示例:
Column names can not be multi-worded, and if they are they need to be within square brackets. Also the parameters in your case can not have spaces. Example:
@AssetType
而不是
@Asset Type
顺便说一下,供应商不是Vandor
[请接受/投票回答或解决方案对您有利,鼓励参与]
By the way, It is Vendor not "Vandor"
[Please accept/up-vote answers or solutions that work for you to encourage participation]
这篇关于类似{&'不正确的语法'Name'附近的错误。"}即将发生。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文