c#查询语句,查询多列?
public static string[] MDBMutiSelect(string Address, string TableName, string KeyColNam, string KeyColValue, string[] TargetColName)
{
int k = TargetColName.Count();
string[] Res=new string[TargetColName.Count()];
OleDbConnection conn;
conn = new OleDbConnection("Provider=Microsoft.Jet.oledb.4.0;Data Source=" + Address + ";Jet Oledb:Engine Type=5");
conn.Open();
//注意空格!!!!!!
string TARGETCOLUNAME=null;
for (int i = 0; i < k;i++ )
{
if (i < k - 1)
{
TARGETCOLUNAME += TargetColName[i] + ",";
}
else
{
TARGETCOLUNAME += TargetColName[i];
}
}
OleDbCommand cmd = new OleDbCommand("select " + TARGETCOLUNAME + " from " + TableName + " where " + KeyColNam + " = '" + KeyColValue + "'", conn);
cmd.CommandType = CommandType.Text;
OleDbDataReader sdr = cmd.ExecuteReader();
for (int i = 0; i < k; i++)
{
MessageBox.Show(sdr[i].ToString());
//Res[i] = sdr[i].ToString();
}
conn.Close();
return Res;
}
调试cmd显示sql为select sssbbb1,sssbbb2 from firsttable11 where sssbbb0 = '三等份';
但是,错误总说,MessageBox.Show(sdr[i].ToString()) 不存在此行?
为什么,请大神解答?如果不可以,还有什么方法吗?