各位好:
我是c#初学者,遇到一个问题希望高手帮忙解决:
我的数据库查询方法如下:
public DataTable GetDataByTbCol(string strTableName, string strColumnName, string strValue)
{
string strSQL = " select * from " + strTableName + " where " + strColumnName + "=" + strValue;
OleDbConnection conn = new OleDbConnection(strDataBase);
OleDbDataAdapter adapter = new OleDbDataAdapter(strSQL, conn);
DataTable tempDT = new DataTable();
adapter.Fill(tempDT);
conn.Close();
if (tempDT.Rows.Count > 0)
{
return tempDT;
}
else
{
return null;
}
}
方法调用如下:(1)DataTable dt = cdb.GetDataByTbCol("Norm", "NormName", "第一行");
(2)DataTable dt = cdb.GetDataByTbCol("Norm", "NormName", "0");
我发现调用的时候第一种调用方法程序会报错,说“至少有一个参数没有指定值”。第二种方法程序可以运行。
请问各位大侠这是什么情况呢?该怎么该才能使参数值是文本类型的时候也能运行?
本人C#初学者,请多指教~~~
我是c#初学者,遇到一个问题希望高手帮忙解决:
我的数据库查询方法如下:
public DataTable GetDataByTbCol(string strTableName, string strColumnName, string strValue)
{
string strSQL = " select * from " + strTableName + " where " + strColumnName + "=" + strValue;
OleDbConnection conn = new OleDbConnection(strDataBase);
OleDbDataAdapter adapter = new OleDbDataAdapter(strSQL, conn);
DataTable tempDT = new DataTable();
adapter.Fill(tempDT);
conn.Close();
if (tempDT.Rows.Count > 0)
{
return tempDT;
}
else
{
return null;
}
}
方法调用如下:(1)DataTable dt = cdb.GetDataByTbCol("Norm", "NormName", "第一行");
(2)DataTable dt = cdb.GetDataByTbCol("Norm", "NormName", "0");
我发现调用的时候第一种调用方法程序会报错,说“至少有一个参数没有指定值”。第二种方法程序可以运行。
请问各位大侠这是什么情况呢?该怎么该才能使参数值是文本类型的时候也能运行?
本人C#初学者,请多指教~~~
string strSQL = " select * from " + strTableName + " where " + strColumnName + "='" + strValue + "'";