0
我正在處理窗體中的某些數據錄入程序,我在按鈕單擊事件上添加以下代碼以在表中添加記錄,但記錄不會添加它會給我一個錯誤的執行非查詢如何在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) 浮子 浮子 float VARCHAR(20) VARCHAR(50) 浮動
你能告訴我們到底是什麼錯誤是你正在得到? – Ben
只是把你所有的語句放在try catch塊中,並找到錯誤。希望這有助於 –
@Jasmeet Singh:不要給予'TextBox1','TextBox2' ...等請給出一些相關的名稱以提高可讀性,並分享你得到的錯誤。 – Prabhat