新手请教个问题
为啥数据库里找不到插入的数据,请各位大侠帮忙看看哪里错了private void button1_Click(object sender, System.EventArgs e)
{
string instr="insert into supm values('"+this.textBox1.Text+"','"+this.textBox2.Text+"')";
a=this.textBox1.Text;
b=this.textBox2.Text;
DBtest db=new DBtest();
try
{
db.open();
db.insert(instr);
MessageBox.Show("已成功插入");
db.close();
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
-----------------------
public class DBtest
{
private SqlConnection conn;
private SqlCommand cmd;
private SqlDataAdapter da;
private SqlDataReader dr;
private DataSet ds;
private DataTable dt;
private DataRow drr;
public DBtest()
{
}
public void open()
{
conn=new SqlConnection("server=.;uid=sa;pwd=;database=test");
conn.Open();
}
public void close()
{
conn.Close();
}
public void insert(string str)
{
string strr=str;
ds=new DataSet();
da=new SqlDataAdapter("select * from supm",conn);
dt=new DataTable();
ds.Tables.Add(dt);
da.Fill(ds,"supm");
// dt.Columns.Add("ID",typeof(string));
// dt.Columns.Add("Name",typeof(string));
drr=ds.Tables[0].NewRow();
drr["ID"]=Form1.a;
drr[1]=Form1.b;
ds.Tables[0].Rows.Add(drr);
da.InsertCommand=conn.CreateCommand();
da.
da.Update(ds,"supm");
}
}
[[italic] 本帖最后由 kenda101 于 2007-12-14 22:04 编辑 [/italic]]