先看两段程序
//添加数据到数据库中
private void button1_Click(object sender, EventArgs e)//添加信息
{
// try
//{
DataSet ds = new DataSet();
OleDbConnection conn = new OleDbConnection("Data Source=F:\\c#.net\\学生信息管理\\denglu.mdb;provider=Microsoft.Jet.OLEDB.4.0");
OleDbDataAdapter daAuthors = new OleDbDataAdapter("Select * From Teacher ", conn);
conn.Open();
oleDbInsertCommand1.Connection = conn;
daAuthors.InsertCommand = oleDbInsertCommand1;
oleDbInsertCommand1.CommandText = "Insert into Teacher(Depart,Grade,clas,Curriculum,Teacher) values( '" + this.comboBox1.Text + " ' ,'" + @comboBox2.Text + "',' " + @comboBox3.Text + " ',' " + @comboBox4.Text + " ',' " + textBox1.Text + " ')";
string s = "Insert into Teacher (Depart,Grade,clas,Curriculum,Teacher) values( '" + this.comboBox1.Text + " ' ,'" + @comboBox2.Text + "',' " + @comboBox3.Text + " ',' " + @comboBox4.Text + " ',' " + textBox1.Text + " ')";
MessageBox.Show(s);
daAuthors.InsertCommand.ExecuteNonQuery();
daAuthors.Fill(ds, "denglu");
dataGrid1.DataSource = ds.Tables[0];
conn.Close();
//}
// catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
}
//修改数据
private void button2_Click(object sender, EventArgs e)//修改信息
{
DataSet ds = new DataSet();
OleDbConnection conn = new OleDbConnection("Data Source=F:\\c#.net\\学生信息管理\\denglu.mdb;provider=Microsoft.Jet.OLEDB.4.0");
OleDbDataAdapter daAuthors = new OleDbDataAdapter("Select * From Teacher ", conn);
string myID = dataGrid1[dataGrid1.CurrentCell.RowNumber, 0].ToString().Trim();
conn.Open();
oleDbUpdateCommand1.Connection = conn;
daAuthors.UpdateCommand = oleDbUpdateCommand1;
oleDbUpdateCommand1.CommandText = "Update Teacher set Depart='" + this.textBox1.Text + " ' ,Grade='" + @textBox2.Text + "',clas=' " + @textBox3.Text + " ',Curriculum=' " + @textBox4.Text + " ',Teacher=' " + @textBox5.Text + " ' where ID= "+ int.Parse(myID);
daAuthors.UpdateCommand.ExecuteNonQuery();
daAuthors.Fill(ds, "denglu");
dataGrid1.DataSource = ds.Tables[0];
conn.Close();
}
[此贴子已经被作者于2007-4-13 10:00:52编辑过]
我的语句:
Dim conn As System.Data.OleDb.OleDbConnection
Dim sStr As String
Dim dr As System.Data.OleDb.OleDbDataReader
???????
sStr = "Provider=MSDAORA.1;pwd=pwd;user id=username;datas ource=kksb"
conn = New System.Data.OleDb.OleDbConnection(sStr)
conn.Open()
sStr = "select * from t_user where username='" & username.Text & "' and pwd='" & pwd.text & "'"
问号部分不会