获取某个字段值
protected System.Data.SqlClient.SqlConnection SqlCon;
protected System.Data.SqlClient.SqlCommand SqlCmd;
protected System.Data.SqlClient.SqlDataReader SqlDR;
protected void OpenSql(SqlDataSource SqlDataSrc)
{
String strSqlSrc = SqlDataSrc.ConnectionString;
SqlCon = new SqlConnection(strSqlSrc);
SqlCon.Open();
}
protected void CloseSql()
{
SqlCon.Close();
}
从数据库表borrow中取出符合要求的字段user_CardID的值。
System.Data.SqlClient.SqlCommand.ExecuteScalar()
// 获取某个字段值
OpenSql(BorrowerSqlDataSource);
SqlCmd = new SqlCommand("select user_CardID from borrower where user_IDNo='" + strIDNo + "'", SqlCon);
SqlDR = SqlCmd.ExecuteReader();
SqlDR.Close();
strRes = Convert.ToString(SqlCmd.ExecuteScalar());
CloseSql();
/**************************************************************************
                 
原文来自博客园——Submarinex的博客: www.cnblogs.com/submarinex/               
 
*************************************************************************/