当前位置:编程学习 > C#/ASP.NET >>

C# access insert语句报错,求指点~

protected void Button1_Click(object sender, EventArgs e)
    {
        string goodsid1 = "'" + TextBox1.Text + "'";
        string goodsname1 = "'" + TextBox2.Text + "'";
        string price1 = "'" + TextBox3.Text + "'";
        string unit1 = "'" + TextBox4.Text + "'";
        string number1 ="'" +  TextBox5.Text + "'";
        string manufacture1 = "'" + TextBox6.Text + "'";
        string manudate1 = "'" + TextBox7.Text + "'";

        string sql1 = goodsid1 + "," + goodsname1 + "," + price1 + "," + unit1 + "," + number1 + "," + manufacture1 + "," + manudate1;

        string sql = "insert into goods (goodsid,goodsname,price,unit,number,manufacture,manudate) values(" + sql1 + ")";
        OleDbCommand cmd = new OleDbCommand(sql, conn); 
        if(cmd.ExecuteNonQuery()==0) 
            Label1.Text = "添加失败";
        else  
            Label1.Text = "添加成功";
       
        conn.Close();
    }

数据库字段全为文本类型 --------------------编程问答-------------------- 把sql语句提取出来看看 --------------------编程问答--------------------  string sql = "insert into goods (goodsid,goodsname,price,unit,number,manufacture,manudate) values('"+TextBox1.Text+"','"+ TextBox2.Text +"','"+TextBox3.Text +"','"+TextBox4.Text+"','"+TextBox5.Text +"','"+TextBox6.Text+"','"+TextBox7.Text +"')";这样试试
还有你这个conn.open()木有
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,