【问题标题】:How to add record in table in windows form applicationwindows窗体应用程序中如何在表中添加记录
【发布时间】: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 :不要给出TextBox1TextBox2 ...等,请给出一些相关名称以提高可读性并分享您遇到的错误类型。

标签: c# asp.net sql data-binding


【解决方案1】:

检查单引号和双引号可能问题出在他们的敌人字符串值我们使用'""'但是对于int

【讨论】:

    猜你喜欢
    • 2011-08-09
    • 2010-09-11
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    相关资源
    最近更新 更多