问题: 编译器错误消息: CS0103: 当前上下文中不存在名称“ClientName”(标识在高亮代码那里),问各位是什么情况
protected void Button4_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "")
{
lblResults.Text = "请输入……";
return;
}
//定义ado对象
string insertSQL;
insertSQL = "SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values('" + @ClientID + " ','"
+@ClientName + "','" + @AddressStr + " ','" + @PostCode + "','" + @Telephone + "','" + @Email + "')";
SqlConnection con = new SqlConnection(myConn);
SqlCommand cmd = new SqlCommand(insertSQL, con);
//添加相应参数……
cmd.Parameters.AddWithValue("@ClientID", TextBox1.Text);
cmd.Parameters.AddWithValue("@ClientName",TextBox2.Text);
cmd.Parameters.AddWithValue("@AddressStr",TextBox3.Text);
cmd.Parameters.AddWithValue("@PostCode",TextBox4.Text);
cmd.Parameters.AddWithValue("@Telephone",TextBox5.Text);
cmd.Parameters.AddWithValue("@Email", TextBox6.Text);
int added = 0;
try
{
con.Open();
added = cmd.ExecuteNonQuery();
lblResults.Text = added.ToString() + "插入记录成功";
}
catch (Exception err)
{
lblResults.Text = "出现错误";
lblResults.Text += err.Message;
}
finally
{
con.Close();
}
//如果插入成功,则刷新下拉框
if (added > 0)
{
fillAutolist();
}
}
6 个解决方案
#1
在线等~~~
#2
'" + @PostCode + "'
这种方式插入 为什么还要是@PostCode
试下这样
这种方式插入 为什么还要是@PostCode
insertSQL = "SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values(@ClientID,@ClientName, @AddressStr ,@PostCode,@Telephone,@Email)";
试下这样
#3
string insertSQL;
insertSQL = "SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values('@ClientID','@ClientName ','@AddressStr','@PostCode ',' @Telephone','@Email')";
insertSQL = "SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values('@ClientID','@ClientName ','@AddressStr','@PostCode ',' @Telephone','@Email')";
#4
SQL 为
"SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values(@ClientID ,@ClientName,@AddressStr, @PostCode , @Telephone ,@Email)"
#5
[code]多谢各位……[/code]
#6
多谢各位
#1
在线等~~~
#2
'" + @PostCode + "'
这种方式插入 为什么还要是@PostCode
试下这样
这种方式插入 为什么还要是@PostCode
insertSQL = "SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values(@ClientID,@ClientName, @AddressStr ,@PostCode,@Telephone,@Email)";
试下这样
#3
string insertSQL;
insertSQL = "SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values('@ClientID','@ClientName ','@AddressStr','@PostCode ',' @Telephone','@Email')";
insertSQL = "SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values('@ClientID','@ClientName ','@AddressStr','@PostCode ',' @Telephone','@Email')";
#4
SQL 为
"SET IDENTITY_INSERT OrderClient ON insert into OrderClient (ClientID, ClientName, AddressStr,PostCode, Telephone ,Email) values(@ClientID ,@ClientName,@AddressStr, @PostCode , @Telephone ,@Email)"
#5
[code]多谢各位……[/code]
#6
多谢各位