嗨,我搜索了很多关于这个主题的内容,但我似乎无法理解用户所做的大部分编码,我对“Boarland C++ builder”很好,并且有很好的经验,但我似乎无法理解MSVS C# 2008 的底部,任何人,我的问题在于登录 SQL 查询,如果那是它的正确名称,似乎搜索和找到的解决方案都没有工作,这是我的代码的一部分“
using System.Data.Sql;
using System.Data.SqlClient;
namespace DMSTestLoginForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connection = @"Data Source=.\SQLExpress;AttachDbFilename=|Data Directory is all set and ready to go|.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(connection);
try
{
con.Open();
//MessageBox.Show("Connection Successful");
}
catch (Exception)
{
//MessageBox.Show("Did not connect"); // connection is successful the issue is down bellow.
}
}
private void lgnbtn_Click(object sender, EventArgs e)
{
string dummyun = uninput.Text;
string dummypw = pwinput.Text;
SqlCommand dummy1 = new SqlCommand("SELECT * FROM nurse WHERE n_id ='"+uninput.Text+"'");
SqlCommand dummy2 = new SqlCommand("SELECT * FROM nurse WHERE n_pw = '"+pwinput.Text+"'");
string dum = Convert.ToString(dummy1);
string dum2 = Convert.ToString(dummy2);
if((dum==dummyun)&&(dum2==dummypw))
MessageBox.Show("Welcome in"); //this message is to test if i logged in or not.
//Form2 Loggedin = new Form2;
//Loggedin.Show();
else
MessageBox.Show("Login failed");
}
问题不在于我的连接字符串,正如我上面提到的,使用 SQL 查询检查用户名/密码是否包含在我的 DB.table 中;哪个是“护士”,或者不是,我知道我创建了很多“字符串”实例,但我陷入了绝望的境地,非常感谢解决方案提供者,在此先感谢。