VS程序里怎么把数据库里的内容显示到textbox控件里 15
我先说一下我的程序。登录界面没问题。链接数据库正常。我现在想实现的功能是。我登录一个学生的学号密码。然后直接跳转到Form2。Form2里面有很多Textbox控件。比如...
我先说一下我的程序。登录界面没问题。链接数据库正常。我现在想实现的功能是。我登录一个学生的学号密码。然后直接跳转到Form2。Form2里面有很多Textbox控件。比如学号,姓名。性别等等什么的。。。就是登录谁的学号就显示谁的信息。别人的不显示。。
展开
2016-01-26 · 知道合伙人软件行家
关注
展开全部
protected void Page_Load(object sender, EventArgs e)
{
getStudent_sourceIdByName()
}
private static SqlConnection connection;
public static SqlConnection Connection
{
get
{
string connectionString = "server=localhost;database=数据库名;uid=sa;password=123456";
if (connection == null)
{
connection = new SqlConnection(connectionString);
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Closed)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Broken)
{
connection.Close();
connection.Open();
}
return connection;
}
private void getStudent()
{
String sql = " SELECT * from dbo.UserInfo ";
SqlCommand cmd = new SqlCommand(sql, Connection);
DataTable dt = (int)cmd.ExecuteReader();
txtName.Text=dt.Rows[0]["name"].ToString();
txtSex.Text=dt.Rows[0]["sex"].ToString();
}
{
getStudent_sourceIdByName()
}
private static SqlConnection connection;
public static SqlConnection Connection
{
get
{
string connectionString = "server=localhost;database=数据库名;uid=sa;password=123456";
if (connection == null)
{
connection = new SqlConnection(connectionString);
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Closed)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Broken)
{
connection.Close();
connection.Open();
}
return connection;
}
private void getStudent()
{
String sql = " SELECT * from dbo.UserInfo ";
SqlCommand cmd = new SqlCommand(sql, Connection);
DataTable dt = (int)cmd.ExecuteReader();
txtName.Text=dt.Rows[0]["name"].ToString();
txtSex.Text=dt.Rows[0]["sex"].ToString();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询