这是我的密码
Conn.Open();
DataTable dt = new DataTable();
DataSet ds = new DataSet();
SqlCommand sqlCmd = new SqlCommand("SELECT * from CurrentDataCR ",Conn);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(ds);
ds.Tables[0].DefaultView.RowFilter = " mst_remote_station_id Like'*9001*'";这里我得到了id 9001的完整行。对于这个id,我只需要一个列值。
发布于 2016-02-05 07:30:02
DataRow[] rows = ds.Tables[0].Select("mst_remote_station_id Like '%9001%'");您也可以这样做,如果您只需要一行,只需在初始查询中选择它。
您还应该在使用它之后释放SqlDataAdapter !您可以使用使用块来完成它
Conn.Open();
DataSet ds = new DataSet();
SqlCommand sqlCmd = new SqlCommand("SELECT * from CurrentDataCR ",Conn);
using(SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd))
{
sqlDa.Fill(ds);
}
ds.Tables[0].Select("mst_remote_station_id Like '%9001%'");我不知道连接是否是全局的,但是使用全局连接是错误的做法,您有连接池,所以对每个查询使用单独的连接。
https://stackoverflow.com/questions/35218482
复制相似问题