首页 > 解决方案 > 为什么数据库没有响应我的 c# PROGRAM?

问题描述

当我运行程序时显示无效登录,请检查用户名和密码。我也检查了我的数据库。数据库没问题。我使用了基于服务的数据库

这是我的登录按钮

private void btnlogin_Click(object sender, EventArgs e)
    {


        try { 

        SqlConnection conn = new SqlConnection(@"Data Source= 
        (LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\Study 
          Material\c#\practicle\ColourManagement\ColourManagement\CMSdatabase.mdf;Integrated 
          Security=True;");


            SqlDataAdapter sda = new SqlDataAdapter("select * from Authenticate where username='" + txtusername.Text + "' and password='" + txtpassword.Text + "' ", conn);

            DataTable dt = new DataTable();

            sda.Fill(dt);

这是我的 if 条件

        if (dt.Rows.Count > 0)
        {
            MessageBox.Show("Login sucess Welcome to Homepage ");
           
        }
        else
        {
            MessageBox.Show("Invalid Login please check username and password");
        }

        
        }
        catch(Exception e01)
        {
            MessageBox.Show("Error"+e01);
        }
    }

标签: c#database

解决方案


推荐阅读