"比如SQL中建学生成绩单后,在C#中,连接SQL后,查找名为“张三”的学生,然后在textbox中显示张三的总成绩,以此为例:
string conn=""数据库连接字符串"";
string str = ""select zcj from table where xm='张三'"";
SqlDataAdapter da = new SqlDataAdapter(str, conn);
DataSet ds = new DataSet();
da.Fill(ds);
textbox.text=ds.tables[0].rows[0][0].Tostring();"
给你个参考代码,你看看吧。 string Computername = System.Net.Dns.GetHostName();
string connectSql = "Data Source=" + Computername + ";Initial Catalog=WebBank//要连接的数据库;Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(connectSql);
sqlConnection.Open();
string sqlCommand1 = "select sum(成绩) from 数据库名 where 姓名='张三'
//查询语句
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand1, sqlConnection);
DataSet ds = new DataSet();
sqlDataAdapter.Fill(ds);
string 张三成绩 = ds.Tables[0].Rows[0]["总成绩"].ToString();
this.textBox1.Text=总成绩;
sqlConnection.Close();
string conn="数据库连接字符串";
string str = "select zcj from table where xm='张三'";
SqlDataAdapter da = new SqlDataAdapter(str, conn);
DataSet ds = new DataSet();
da.Fill(ds);
textbox.text=ds.tables[0].rows[0][0].Tostring();
select sum(成绩) from 成绩表 where username='张三'
别人要的是求总成绩,求总成绩才是关键。呵呵