日期:2014-05-18 浏览次数:21195 次
Sqlcommond cmd =new Sqlcommond(); textBox.Text=cmd.ExecuteScalar().ToString();
------解决方案--------------------
using System.Data.SqlClient; using(SqlConnection con = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=Northwind")) { con.Open(); string strsql6 = "select count(sno) from student where cno='" + class1 + "' and cet4>425"; SqlCommand cmd = new SqlCommand(strsql6,con); this.TextBox1.Text = cmd.ExecuteScalar().ToString(); }
------解决方案--------------------
using System.Data.SqlClient; using(SqlConnection con = new SqlConnection("Data Source=.;initial catalog=Northwind;user id=sa;password=sa")) { string strsql6 = "select count(sno) from student where cno=@class1 and cet4>425"; using(SqlCommand cmd = new SqlCommand(strsql6,con)) { con.Open(); cmd.Parameters.AddWithValue("@class1",class1); this.TextBox1.Text = cmd.ExecuteScalar().ToString(); } }