如何实现登陆窗体,即输入用户名和密码后才能进入应用程序?用户,密码得从数据库获得。 using System.Data.SqlClient; namespace _图书馆管理系统_
{
public partial class Frm_User : Form
{
public Frm_User()
{
InitializeComponent();
} private void button1_Click_1(object sender, EventArgs e)//确定按钮
{
SqlConnection con = new SqlConnection("server=.;database=Library;Integrated Security=USERB");
con.Open();
//select * from USERB where name='ganqiyin' and password='123456'
SqlCommand cmd = new SqlCommand("select * from USERB where name='" + textBox1.Text + "'and password='" + textBox2.Text + "'");
cmd.ExecuteScalar();
if ();
{
Frm_Main Main = new Frm_Main();
Main.Show();
this.Hide();
}
} 我就会一点,请大家帮我下,谢谢!
{
public partial class Frm_User : Form
{
public Frm_User()
{
InitializeComponent();
} private void button1_Click_1(object sender, EventArgs e)//确定按钮
{
SqlConnection con = new SqlConnection("server=.;database=Library;Integrated Security=USERB");
con.Open();
//select * from USERB where name='ganqiyin' and password='123456'
SqlCommand cmd = new SqlCommand("select * from USERB where name='" + textBox1.Text + "'and password='" + textBox2.Text + "'");
cmd.ExecuteScalar();
if ();
{
Frm_Main Main = new Frm_Main();
Main.Show();
this.Hide();
}
} 我就会一点,请大家帮我下,谢谢!
解决方案 »
- exe无法启动
- 我的代码执行后生成了没有文件名的txt文件
- foreach 和 for 的效率,提供测试结果,高手来帮分析下!
- xtrareport 导出pdf问题
- 一个安装。net的问题
- 如何将sqlCommand对象的查询结果填充到 DataTable DataView DataSet DataViewManager 作为数据源提供给 DataGrid
- c#中如何在设计页面的html代码中调用代码文件中的变量?有没有这种办法的?给分100
- 关于程序员都喜欢用先进的技术,呵呵
- 类型在未被引用的程序集中定义?
- C# MySql.Data.dll
- 在Asp.Net怎么优化频繁对数据库操作问题???
- 求一个provider。convert.ToString(int16,provider)
{}
private void button1_Click_1(object sender, EventArgs e)//确定按钮
{
SqlConnection con = new SqlConnection("server=.;database=Library;Integrated Security=USERB");
con.Open();
//select * from USERB where name='ganqiyin' and password='123456'
SqlCommand cmd = new SqlCommand("select * from USERB where name='" + textBox1.Text + "'and password='" + textBox2.Text + "'",conn);
[color=#FF0000SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);[/color]
if (reader.HasRows)
{
Frm_Main Main = new Frm_Main();
Main.Show();
this.Hide();
}
}
{
SqlConnection con = new SqlConnection("server=.;database=Library;Integrated Security=USERB");
con.Open();
//select * from USERB where name='ganqiyin' and password='123456'
SqlCommand cmd = new SqlCommand("select * from USERB where name='" + textBox1.Text + "'and password='" + textBox2.Text + "'",conn);
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows) //判断是否能够读取到数据
{
Frm_Main Main = new Frm_Main();
Main.Show();
this.Hide();
}
}
假如数据库里为string,则可写成
string name=cmd.ExecuteScalar();
if(!string.IsNullOrEmpty(name)||name!=null)
{
执行你的操作
}
private void button1_Click_1(object sender, EventArgs e)//确定按钮
{
SqlConnection con = new SqlConnection("server=.;database=Library;Integrated Security=USERB");
con.Open();
//select * from USERB where name='ganqiyin' and password='123456'
SqlCommand cmd = new SqlCommand("select * from USERB where name='" + textBox1.Text + "'and password='" + textBox2.Text + "'",con);
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows) //判断是否能够读取到数据
{
Frm_Main Main = new Frm_Main();
Main.Show();
this.Hide();
}
}