问一下数据库取值问题
我想取一个数据库中同一列不同记录的值,乍么取呀?我会取同一记录不同列的值,但这样我就不会了,请高手指教!!
最好给些代码
在线等
------解决方案--------------------sqlconncetion...
conn.open()
sqlcommand...
sqldataread dr=cmd.ExecuteReader();
while(dr.read())
{
...=dr[ "数据库字段 "]
}
conn.Close();
不要给大钻石分了 他用不到的
------解决方案--------------------你可以这样!!!!!
public float GetNSFBL(out float N2,out float N3)
{
OleDbConnection dbCntGuize;
string sqlstr;
string dbpvd;
string dbname;
dbpvd = "Provider=Microsoft.Jet.OLEDB.4.0 ";
dbname = "Data Source = " + ParentDir(Directory.GetCurrentDirectory(), 4) + "\\施肥数据库\\果类施肥.mdb ";
dbCntGuize = new OleDbConnection(dbpvd + "; " + dbname);
dbCntGuize.Open();
//打开“施肥比例1”表
OleDbCommand dbcmd;
sqlstr = "select * from 施肥比例1 ";
dbcmd = new OleDbCommand(sqlstr, dbCntGuize);
OleDbDataReader myreader = dbcmd.ExecuteReader();
object N1 = 0;
N2 = 0;
N3 = 0;
while (myreader.Read())
{
N1 = myreader[ "N "];
N2 = myreader[ "N "];
N3 = myreader[ "N "];
}
myreader.Close();
return N1;
}
测试过了 没错!!!!