我用SQL查询结果只会返回一个值,如何把查询得到的这个值赋值给一个变量比如a?
我的代码如下: OleDbDataAdapter custDA = new OleDbDataAdapter();
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\Data Center\\ReportYear.mdb");
OleDbCommand aCommand = new OleDbCommand("select [代码] from ID where [序号] = '" + a + "' ", aConnection); aConnection.Open();
DataSet ds = new DataSet();
custDA.Fill(ds);不知接下去如何操作。
我的代码如下: OleDbDataAdapter custDA = new OleDbDataAdapter();
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\Data Center\\ReportYear.mdb");
OleDbCommand aCommand = new OleDbCommand("select [代码] from ID where [序号] = '" + a + "' ", aConnection); aConnection.Open();
DataSet ds = new DataSet();
custDA.Fill(ds);不知接下去如何操作。
string b = (string)aCommand.ExecuteScalar(); 为什么不对?
我这个a是整型,所以不用''来括起来。
"select [代码] from ID where [序号] = " + a + " "