获取某个字段值

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();

 

posted @ 2011-12-22 11:07  SubmarineX  阅读(401)  评论(0编辑  收藏  举报