日期:2014-05-17 浏览次数:20548 次
int result = 0;
string connstr = "Data Source=(local);Initial Catalog=DatabaseName; User ID=UserName; Password=Pwd; ";
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connstr);
conn.Open();
string sql = "select Placed from enterprise";//这里没个where条件么?比如where id=1之类的
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, conn);
object obj = cmd.ExecuteScalar();
if (obj != null)
{
result = int.TryParse(obj.ToString(),out result)==true?Convert.ToInt32(obj):result;
}