问题描述
代码如下,求教usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace图书管理系统{publicpartialclass图书信息:Form{stringdataMember;public图书信息(){InitializeComponent();dataMember="图书表";BuildData();}privatevoidBuildData(){Sqla=newSql();stringsqlStr="select*from图书表";SqlConnectioncon=newSqlConnection(a.DJ());SqlDataAdapteradapter=newSqlDataAdapter(sqlStr,con);DataSetds=newDataSet();adapter.Fill(ds,dataMember);this.dataGridView1.DataSource=ds.Tables[dataMember];}privatevoiddataGridView1_CellContentClick(objectsender,DataGridViewCellEventArgse){}privatevoid图书信息_Load(objectsender,EventArgse){//TODO:这行代码将数据加载到表“book_manage_systemDataSet.图书表”中。您可以根据需要移动或移除它。this.图书表TableAdapter.Fill(this.book_manage_systemDataSet.图书表);}privatevoidbutton1_Click(objectsender,EventArgse){if(textBox1.Text==""||textBox2.Text==""||textBox3.Text==""||textBox4.Text==""||textBox6.Text==""||textBox7.Text==""||textBox8.Text==""){MessageBox.Show("输入不能为空,重新输入");textBox1.Text="";textBox2.Text="";textBox3.Text="";textBox4.Text="";textBox6.Text="";textBox7.Text="";textBox8.Text="";}else{try{Sqla=newSql();SqlConnectioncon=newSqlConnection(a.DJ());con.Open();stringcmdstring="insertinto图书表values('"+this.textBox1.Text+"','"+this.textBox2.Text+"','"+this.textBox3.Text+"','"+this.textBox4.Text+"','"+this.maskedTextBox1.Text+"','"+this.textBox6.Text+"','"+this.textBox7.Text+"','"+this.textBox8.Text+"')";SqlCommandcmd=newSqlCommand(cmdstring,con);cmd.ExecuteNonQuery();BuildData();con.Close();}catch{MessageBox.Show("请按照格式真确输入");}}}privatevoidbutton4_Click(objectsender,EventArgse){this.Close();}privatevoidbutton2_Click(objectsender,EventArgse){if(textBox1.Text==""){MessageBox.Show("输入不能为空,重新输入");textBox1.Text="";}else{try{Sqla=newSql();SqlConnectioncon=newSqlConnection(a.DJ());con.Open();stringcmdstring="deletefrom图书表where图书编号='"+this.textBox1.Text+"'";SqlCommandcmd=newSqlCommand(cmdstring,con);cmd.ExecuteNonQuery();BuildData();con.Close();}catch{MessageBox.Show("请真确输入图书编号");}}}privatevoiddataGridView1_CellContentClick_1(objectsender,DataGridViewCellEventArgse){}privatevoidtextBox1_TextChanged(objectsender,EventArgse){}}}
解决方案
解决方案二:
自己调试,先确定那条代码报错,再检查sql语句是否正确,特别是insert,字段要对应
解决方案三:
断点,调试,把错误的代码贴上来!
解决方案四:
调试,就到这一步就执行不了
解决方案五:
Sql类的构造方法的代码贴来看下
解决方案六:
Sql是个神马。
解决方案七:
Sqla=newSql();看代码内容va.DJ()是应该返回:"server=.;database=数据库;uid=sa;pwd=sa";调试时你看一下,可能问题出在这里,如果不是,直接用下面这样试一下SqlConnectioncon=newSqlConnection("server=.;database=数据库;uid=sa;pwd=sa");