Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用mysql server 5.7.14和workbench 6.3以及c#窗口表单应用程序创建登录_C#_Mysql - Fatal编程技术网

使用mysql server 5.7.14和workbench 6.3以及c#窗口表单应用程序创建登录

使用mysql server 5.7.14和workbench 6.3以及c#窗口表单应用程序创建登录,c#,mysql,C#,Mysql,我正在尝试对正在输入我的应用程序的用户进行检查(登录)。我制作了一个数据库和表,分别命名为“mydb”、“employee”。我已经在employee表的uname和pasword列中输入了用户名和密码。我想做的是,用户输入的用户名和密码是否有效?这意味着它是否存在于employee表中?如果是,则允许访问,如果不是,则拒绝访问。 为此,我使用visual studio 2013 ultimate在我的c#窗口表单应用程序中编写了以下代码 try { string myconnectio

我正在尝试对正在输入我的应用程序的用户进行检查(登录)。我制作了一个数据库和表,分别命名为“mydb”、“employee”。我已经在employee表的uname和pasword列中输入了用户名和密码。我想做的是,用户输入的用户名和密码是否有效?这意味着它是否存在于employee表中?如果是,则允许访问,如果不是,则拒绝访问。 为此,我使用visual studio 2013 ultimate在我的c#窗口表单应用程序中编写了以下代码

try
{
    string myconnection = "datasource=localhost; port=3306; username=root; password=shaban;  ";
    MySqlCommand selectcommand = new MySqlCommand(" slect * from mydb.employee where uname= "+this.username_txt.Text+" and pasword = "+this.pasword_txt.Text+"", myconn);

    MySqlDataReader myreader;
    myconn.Open();
    myreader = selectcommand.ExecuteReader();
    int count = 0;
    while (myreader.Read())
    { 
       count = count + 1; 
    }

    if (count == 1)
    { 
        MessageBox.Show("username and pasword is correct"); 
    }
    else if (count > 1)
    { 
        MessageBox.Show("Duplicate username and password...! Access Denied "); 
    }
    else 
    { 
        MessageBox.Show(" username and pasword not existing.. Try again" ); 
    }
    myconn.Close();
}
catch (Exception ex)
{    
    MessageBox.Show(ex.Message);    
}

首先,您的查询“slect”中有输入错误 其次,WHERE子句中缺少单引号

where uname= '"+this.username_txt.Text+"' and pasword = '"+this.pasword_txt.Txt+"'"'
如果这些事情解决了你的问题,请告诉我。我们将看到下一件事


还要具体说明您面临的错误或问题。

slect
这是一个主要的打字错误。告诉我们这不是一个,否则你的问题可能会因为它而关闭,因为它是一个“打字错误”。如果uname和pasword是文本字段,那么你没有正确引用你的值,但这不是一个有效的修复方法。试着理解为什么以及如何使用参数化查询阅读如何使用参数构造查询更好地理解为
参数化查询
除了发布代码之外,还要阅读
SQL注入是什么。。请说明问题所在,更不用说修复此代码的糟糕格式。另外,当您仅检查用户名和密码时,为什么要从表中选择*。。你应该在列上选择你要检查的内容,而不是所有的内容。当我们检查时,散列你的密码,不要保存为明文。