|
楼主 |
发表于 2015-4-20 17:19:24
|
显示全部楼层
好的,谢谢提醒亲。但是还是没有解决,mydata是我建的数据库,user是其中的表。这是全部代码
我建的类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace stu
{
class DBconn
{
public static SqlConnection stucon()
{
return new SqlConnection("server=.;database=mydata;uid=sa;pwd=yq1993311");
}
}
}
登陆界面的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace stu
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
private void bt_denglv_Click(object sender, EventArgs e)
{
SqlConnection conn = stu.DBconn.stucon();
conn.Open();
SqlCommand cmd = new SqlCommand("Select count(*) from user where 用户名='" + username.Text + "' and 密码='" + password.Text + "'", conn);
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
{
Form2 frm = new Form2();
frm.Show();
this.Hide();
}
else
MessageBox.Show("用户名和密码错误");
}
}
}
|
|