问个简单的问题
ViewState[ "count "]= "select count(*) from ticketinfo where BarCodeID LIKE '% " + this.TextBox1.Text + "% ' ";
public string getcount()
{
string strReturn= "NULL ";
SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[ "ConStr "]);
SqlCommand cmd=new SqlCommand(ViewState[ "count "].ToString(),con);
cmd.Connection.Open();
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
strReturn=dr.ToString();
}
cmd.Connection.Close();
return strReturn;
}
请问如果用上面那个SQL语句该怎么改 我那样写不对
[解决办法]
cmd.Connection.Open();
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
strReturn=dr.ToString();
}
cmd.Connection.Close();
return strReturn;
=>
con.Open();
object obj = cmd.ExecuteScalar();
con.Close();
return obj.ToString();