数据库读取 用户登陆信息 分别显示在 Comcobox 下列表中和 text 文本框中
一下我写的代码 帮忙看看 总是出错!!!!!!!!
private void bntOK_Click(object sender, System.EventArgs e) {
string password=txtPassword.Text.ToString();
string name=cobUserName.SelectedItem.ToString(); string conn="server=(local);"+"intetrated security=SSPI;"+"database=kechengsheji";
string mysql="select 用户名 密码 from usertable";
SqlConnection myConnection=new SqlConnection(conn);
SqlCommand cmd=new SqlCommand(mysql,myConnection);
myConnection.Open();
string Password=Convert.ToString(cmd.ExecuteScalar());
if (Password==password)
{
frmMain a=new frmMain();
a.ShowDialog();}
else
{
MessageBox.Show("密码输入错误!");
}
myConnection.Close();
一下我写的代码 帮忙看看 总是出错!!!!!!!!
private void bntOK_Click(object sender, System.EventArgs e) {
string password=txtPassword.Text.ToString();
string name=cobUserName.SelectedItem.ToString(); string conn="server=(local);"+"intetrated security=SSPI;"+"database=kechengsheji";
string mysql="select 用户名 密码 from usertable";
SqlConnection myConnection=new SqlConnection(conn);
SqlCommand cmd=new SqlCommand(mysql,myConnection);
myConnection.Open();
string Password=Convert.ToString(cmd.ExecuteScalar());
if (Password==password)
{
frmMain a=new frmMain();
a.ShowDialog();}
else
{
MessageBox.Show("密码输入错误!");
}
myConnection.Close();
myConnection.Open();
把myConnection.Open();放在 SqlCommand cmd=new SqlCommand(mysql,myConnection);
上面
未将对象引用设置到对象的实例!
string name=cobUserName.SelectedItem.ToString();
就是这个!
高手给指点一下!
cobUserName没有选中任何东西吧?
还是cobUserName本身就是null?
问题好像就是处在cobUserName没有选中任何东西!!!
请问怎么设置一下?
是不是用dataadapter 生成数据集??
我的意思的 读取数据库中 usertable 表中的 用户名和密码
用户名为多个 这样用Comcobox 下拉列表 显示出来
在密码正确的情况下 程序进入下一个窗体?
应该是Combobox吧,你把里面的text属性写上值,这个就是你的默认值了。
我的想法 是直接读取数据库中的数据 填充到 Combobox中?
这样代码怎么实现?或者别的方法?
xxx是你从数据库中读出的值。
上面我写的代码 希望您帮该一下 能实现这个功能。。(读取数据库的数据,判断密码的正误!)
我自己写总是出错。。哭了!
可以执行吗? 差个逗号吧