Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.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
C# 使用MySQL中的存储过程在C中登录_C#_Mysql_Wpf - Fatal编程技术网

C# 使用MySQL中的存储过程在C中登录

C# 使用MySQL中的存储过程在C中登录,c#,mysql,wpf,C#,Mysql,Wpf,我正在制作一个userform,它将首先登录到数据库服务器,然后从一个包含用户详细信息的表中进行身份验证 我已经在MySQL中创建了一个存储过程,我想从我的用户表单中使用该存储过程登录 这是我下面的代码,我无法找出我遗漏了什么。请帮忙。 错误:找不到数据库 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using

我正在制作一个userform,它将首先登录到数据库服务器,然后从一个包含用户详细信息的表中进行身份验证

我已经在MySQL中创建了一个存储过程,我想从我的用户表单中使用该存储过程登录

这是我下面的代码,我无法找出我遗漏了什么。请帮忙。 错误:找不到数据库

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;

namespace OmegaServe
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                string myconnection = "datasource=" + Hostname.Text + ";port=" + PortNumber.Text + ";username=" + DBuname.Text + ";password=" + DBupass.Password + "";
                MySqlConnection myConn = new MySqlConnection(myconnection);
                //MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
                //MySqlCommand SelectCommand = new MySqlCommand("select name from " + Database.Text + ".userdetails where emailID='" + LoginID.Text + "' and password='" + LoginPass.Password + "';", myConn);
                //MySqlCommandBuilder cd = new MySqlCommandBuilder(myDataAdapter);
                MySqlCommand SelectCommand = new MySqlCommand("authenticateUser", myConn);
                SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
                MySqlParameter email = new MySqlParameter("@iEmailID", LoginID.Text);
                MySqlParameter password = new MySqlParameter("@iPassword", LoginPass.Password);
                MySqlParameter ip = new MySqlParameter("@iIpAddr", "00:00:00:00");
                MySqlParameter role = new MySqlParameter("@iRoleId", 1);
                SelectCommand.Parameters.Add(email);
                SelectCommand.Parameters.Add(password);
                SelectCommand.Parameters.Add(ip);
                SelectCommand.Parameters.Add(role);
                myConn.Open();

                MySqlDataReader myreader;

                myreader = SelectCommand.ExecuteReader();
                int count = 0;
                while (myreader.Read())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    MessageBox.Show("Login Successful");

                }
                else if (count > 1)
                {
                    MessageBox.Show("Duplicate Users Available");

                }
                else
                {
                    MessageBox.Show("Login Failed");
                    myConn.Close();

                }





            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }
    }
}

您的连接字符串的格式应为:

connectionString="server=myServerAddress;port=1234;username=myUsername;password=myPassword;database=myDataBase"

我怀疑您是否通过datasource=+Hostname捕获了服务器和数据库名称。Text

您似乎缺少对给定代码无法工作的原因的解释。添加了错误消息。对不起,错过了。