C#数据库 连接语法 我创建了一个两个textBox 一个Button 在上面添完帐号和密码应该如何创建连接让他们到数据库去搜索这个帐号和密码是否真确如果不正确的话点完button显示 密码或者帐户错误正确的话则弹出另外一个窗体 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string password=txtPassword.Text.ToString(); string name=txtUserName.SelectedItem.ToString(); string connecitonString="server=(local);"+"intetrated security=SSPI;"+"database=App"; string mysql="select 用户名 密码 from usertable"; SqlConnection myConnection=new SqlConnection(connecitonString); myConnection.Open(); SqlCommand cmd=new SqlCommand(mysql,myConnection); string Password=Convert.ToString(cmd.ExecuteScalar()); if (Password==password) { frmMain a=new frmMain(); a.ShowDialog();} else { MessageBox.Show("密码输入错误!"); } myConnection.Close();以上代码仅供参考! 以下是我以前做的一个系统登陆的代码,仅供参考private void ButGO_Click(object sender, System.EventArgs e) { if(comboBox1.Text.ToString().Trim()=="请选择") { MessageBox.Show("请选择服务器!"); return; } IniFile ini= new IniFile(Application.StartupPath+@"\database.ini") ; ini.IniWriteValue("database","server",comboBox1.Text.ToString ().Trim()); string query="select count(*) as a from zz_admin where ID='"+this.TxtID.Text+"'"; con().Open(); SqlDataAdapter da = new SqlDataAdapter(query,con()); DataSet ds = new DataSet(); da.Fill(ds,"zz_admin") ; int aa =(int)ds.Tables[0].Rows[0][0]; con().Close(); if (aa ==0) { MessageBox.Show("管理员帐号输入有误,请重新输入!"); } else { string query1="select PWD,DEGREE,used from zz_admin where ID='"+this.TxtID.Text+"'"; SqlDataAdapter da1 = new SqlDataAdapter(query1,con()); DataSet ds1 = new DataSet(); da1.Fill(ds1,"zz_admin") ; pwd=ds1.Tables["zz_admin"].Rows[0][0].ToString(); string dgr=ds1.Tables["zz_admin"].Rows[0][1].ToString(); string used=ds1.Tables["zz_admin"].Rows[0][2].ToString(); if(pwd.Trim() != TxtPWD.Text.Trim()) { MessageBox.Show("管理员密码输入有误,请重新输入!"); con().Close(); return; } if(dgr.Trim() == "信采员") { MessageBox.Show("权限不足,请联系超级管理员!"); con().Close(); return; } if(used.Trim() != "启用") { MessageBox.Show("帐号被封,请联系管理员!"); con().Close(); return; } con().Close(); UserPWD=TxtPWD.Text.Trim(); UserName=TxtID.Text.Trim(); wyfxglht frm= new wyfxglht(UserName); frm.Show(); this.Hide(); } } 请参照http://www.connectionstrings.com 做登陆框要用到哪些控件 我用的是SQL数据库 问一个菜鸟问题 关于Attributes.Add的问题 C#用户控件的事件处理问题? 为什末我的单选按钮可以多选阿 并且选中了就不能消掉了? Socket通信 请问,如何在窗体上添加一条线。 SQL 查询语中词组 如何让TabControl自由的Drag and Drop? JAVASCRIPT类型转换问题 在c#中是否有象java中的drawstring()这样的方法?万分感谢! 我在C#中连接一台远端的Oracle 9i数据库,报无监听器连接的错误!请高手帮我看看! System.Reflection.Emit自动生成调用储存过程的实现问题
string name=txtUserName.SelectedItem.ToString(); string connecitonString="server=(local);"+"intetrated security=SSPI;"+"database=App";
string mysql="select 用户名 密码 from usertable";
SqlConnection myConnection=new SqlConnection(connecitonString);
myConnection.Open();
SqlCommand cmd=new SqlCommand(mysql,myConnection);
string Password=Convert.ToString(cmd.ExecuteScalar());
if (Password==password)
{
frmMain a=new frmMain();
a.ShowDialog();}
else
{
MessageBox.Show("密码输入错误!");
}
myConnection.Close();
以上代码仅供参考!
private void ButGO_Click(object sender, System.EventArgs e)
{
if(comboBox1.Text.ToString().Trim()=="请选择")
{
MessageBox.Show("请选择服务器!");
return;
}
IniFile ini= new IniFile(Application.StartupPath+@"\database.ini") ;
ini.IniWriteValue("database","server",comboBox1.Text.ToString ().Trim());
string query="select count(*) as a from zz_admin where ID='"+this.TxtID.Text+"'";
con().Open();
SqlDataAdapter da = new SqlDataAdapter(query,con());
DataSet ds = new DataSet();
da.Fill(ds,"zz_admin") ;
int aa =(int)ds.Tables[0].Rows[0][0];
con().Close();
if (aa ==0)
{
MessageBox.Show("管理员帐号输入有误,请重新输入!");
} else
{
string query1="select PWD,DEGREE,used from zz_admin where ID='"+this.TxtID.Text+"'";
SqlDataAdapter da1 = new SqlDataAdapter(query1,con());
DataSet ds1 = new DataSet();
da1.Fill(ds1,"zz_admin") ;
pwd=ds1.Tables["zz_admin"].Rows[0][0].ToString();
string dgr=ds1.Tables["zz_admin"].Rows[0][1].ToString();
string used=ds1.Tables["zz_admin"].Rows[0][2].ToString();
if(pwd.Trim() != TxtPWD.Text.Trim())
{
MessageBox.Show("管理员密码输入有误,请重新输入!");
con().Close();
return;
}
if(dgr.Trim() == "信采员")
{
MessageBox.Show("权限不足,请联系超级管理员!");
con().Close();
return;
}
if(used.Trim() != "启用")
{
MessageBox.Show("帐号被封,请联系管理员!");
con().Close();
return;
}
con().Close();
UserPWD=TxtPWD.Text.Trim();
UserName=TxtID.Text.Trim();
wyfxglht frm= new wyfxglht(UserName);
frm.Show();
this.Hide();
}
}
http://www.connectionstrings.com
我用的是SQL数据库