急求C#能用来执行SQL查询语句~并且取得查询结果然后赋值给String变量的方法!!

2024-10-29 22:59:31
推荐回答(1个)
回答1:

string connectionstring="连接字符串";
string SQLString ="SQL命令";
string RE="";
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
DataSet ds = new DataSet();
try
{
connection.Open();
OleDbDataAdapter command = new OleDbDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.OleDb.OleDbException ex)
{
;
}
RE= ds.Tables[0].Row[0][0];
}