小弟想连接到本地数据库
通过筛选获得一个值赋给一个TEXTBOX里
例如表如下
id name score
01 Tom 70
02 Mary 80在SQL上查询"select id from point where name='Tom'"
结果为 01
我的源代码如下:
string connectionString = GetConnectionString();
SqlConnection sqlConnection = new SqlConnection(connectionString);
sqlConnection.Open();
string SQLStmt = " SELECT ID FROM point WHERE Name='Tom'";
SqlCommand myCommand = new SqlCommand(SQLStmt, sqlConnection);sqldata.Text = ??????????????????????????????????????????????????????????????????;
sqlConnection.Close();请问"???..."哪里应该怎样添加源代码
才能把结果输出到TEXTBOX里呢?
通过筛选获得一个值赋给一个TEXTBOX里
例如表如下
id name score
01 Tom 70
02 Mary 80在SQL上查询"select id from point where name='Tom'"
结果为 01
我的源代码如下:
string connectionString = GetConnectionString();
SqlConnection sqlConnection = new SqlConnection(connectionString);
sqlConnection.Open();
string SQLStmt = " SELECT ID FROM point WHERE Name='Tom'";
SqlCommand myCommand = new SqlCommand(SQLStmt, sqlConnection);sqldata.Text = ??????????????????????????????????????????????????????????????????;
sqlConnection.Close();请问"???..."哪里应该怎样添加源代码
才能把结果输出到TEXTBOX里呢?
SqlConnection sqlConnection = new SqlConnection(connectionString); string SQLStmt = " SELECT ID FROM point WHERE Name='Tom'";
SqlCommand myCommand = new SqlCommand(SQLStmt, sqlConnection); sqlConnection.Open();
sqldata.Text = myCommand.ExecuteScalar().ToString();
sqlConnection.Close();
using (SqlDataReader dr = myCommand.ExecuteReader())
{
if (dr.Read())
{
sqldata.Text = dr.GetString(0);
}
dr.Close();
}