[英]How to add record in table in windows form application
i am working on some data entry program in windows form, i write the following code on button click event to add records in table but records doesn't add it gives me an error of execute non query 我正在使用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";
}
}
data type used:- varchar(10) varchar(100) varchar(20) date varchar(25) date char(3) float float float varchar(20) varchar(50) float 使用的数据类型:-varchar(10)varchar(100)varchar(20)date varchar(25)date char(3)float float varchar(20)varchar(50)float
检查单引号和双引号可能是问题所在,因为我们使用了“”“',但是对于int
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.