日期:2014-05-19  浏览次数:20809 次

C#中操作数据库,请高手指点 谢谢大家了在线等急!!!
如何从ACCESS数据库中读出数据   ,赋给一个变量,
  比如说数据库中有pname,dname,zname这样三列,查询数据库时条件满足pname   =   'll ';查询的数据dname   ,   pname   分别赋给变量m,n;怎么做啊?我都做了快两天了。请各位帮帮忙吧

------解决方案--------------------
public void ReadMyData(string myConnString) {
string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders ";
OdbcConnection myConnection = new OdbcConnection(myConnString);
OdbcCommand myCommand = new OdbcCommand(mySelectQuery,myConnection);
myConnection.Open();
OdbcDataReader myReader;
myReader = myCommand.ExecuteReader();
// Always call Read before accessing data.
while (myReader.Read()) {
Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
}
// always call Close when done reading.
myReader.Close();
// Close the connection when done with it.
myConnection.Close();
}

自己看着改吧...
------解决方案--------------------
this.oleDbConnection1.Open();
string StrSql = "select * Form 11 where ";
StrSql+= " pname= ' "+this.textBox4.Text+ " ' ";
this.oleDbCommand1.CommandText = StrSql;
this.oleDbCommand1.Connection = this.oleDbConnection1;
OleDbDataReader rs = oleDbCommand1.ExecuteReader();
if (rs.Read())
{
this.textBox1.Text = rs[2].ToString();
this.textBox2.Text = rs[1].ToString();
this.textBox3.Text = rs[0].ToString();
}
.....
这样改吧