簡體   English   中英

如何在Windows窗體應用程序的表中添加記錄

[英]How to add record in table in windows form application

我正在使用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)date varchar(25)date char(3)float float varchar(20)varchar(50)float

檢查單引號和雙引號可能是問題所在,因為我們使用了“”“',但是對於int

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM