asp.net(c#)如何把用SQL查询的结果赋值给变量

来源:百度知道 编辑:UC知道 时间:2024/06/17 12:36:39

可以看看ADO.net相关的资料。
例子:
string connStr = System.Configuration.ConfigurationSettings.AppSettings[0];
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
string sqlStr = "select 年龄 from [tablename] where 姓名 = '" + Request["姓名"]+"'" ;
SqlCommand cmd = new SqlCommand(sqlStr,conn);
SqlDataReader dr=cmd.ExecuteReader();
dr.Read();
string studentAge = dr["年龄"].ToString();
label.Text = studentAge;
.........

string aa = ds.Table[0].Rows[0][0].ToString();
如果你把你的代码发上来,我可以给你写,但是最好还是自己好好学一下,很简单的。