【发布时间】:2014-05-06 04:43:58
【问题描述】:
我正在开发一些 Windows 窗体中的数据输入程序,我在按钮单击事件上编写以下代码以在表中添加记录,但记录没有添加它给我一个执行非查询的错误
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=JASMEETSINGH-PC;Initial Catalog=Desnet;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Insert into BillEntry values('" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + dateTimePicker1.DataBindings + "', '" + textBox4.Text + "', '" + dateTimePicker2.DataBindings + "', '" + radioButton1.DataBindings + "', '" + radioButton2.DataBindings + "', '" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "')", con);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
label15.Text = "Record Added Successfully";
}
}
使用的数据类型:- varchar(10) varchar(100) varchar(20) 日期 varchar(25) 日期 字符(3) 漂浮 漂浮 漂浮 varchar(20) varchar(50) 浮动
【问题讨论】:
-
您能准确告诉我们您遇到的错误是什么吗?
-
只需将所有语句放在 try catch 块中并找出错误。希望这会有所帮助
-
@Jasmeet Singh :不要给出
TextBox1、TextBox2...等,请给出一些相关名称以提高可读性并分享您遇到的错误类型。
标签: c# asp.net sql data-binding