C#软件不会连接到我的localhost mysql Xampp说sqlException未处理

问题描述 投票:-2回答:1

我已经完成了设计我的项目软件,将我的软件文本框中的信息传递给我的本地mysql xampp数据库。

我有此错误消息

请帮助下面的代码。我从下面的代码中弄错了什么?

我有两个文本框,即“种子”和“密码”和按钮“加密”和“解密”

namespace seed
{
    public partial class CryptSeed : Form
    {
        public CryptSeed()
        {
            InitializeComponent(); 
        }

        SqlConnection con = new SqlConnection("server=localhost;user id=seedcrypt;persistsecurityinfo=True;database=seed;");

        private void Form1_Load(object sender, EventArgs e)
        {
            con.Open();
            string query = "INSERT INTO info ('id','seed','password','ip') VALUES (NULL,'"+seed.Text+ "','" +password.Text+ "',NULL)";
            SqlDataAdapter SDA = new SqlDataAdapter(query, con);
            SDA.SelectCommand.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("INSERTED SUCCESSFULLY !!! ");  
        }
    }
}
c# mysql
1个回答
0
投票

如果你连接到mysql数据库,那你就错了。首先你需要mysqlconnector for c#。你究竟要做什么?保存?读?

 public partial class CryptSeed : Form
{
    public CryptSeed()
    {
        InitializeComponent(); 
    }
       //you will need to specify the port Mysql uses:3306

    private void Form1_Load(object sender, EventArgs e)
    {      
           //  If you are saving data you cant do it here.
          //  But still will show you how to do it in a button //click 
     //event.                
    }
    private void button1_Click(object sender,EventArgs e)
    {MySqlConnection con = new MySqlConnection("server=localhost;port=3306;  username=seedcrypt;database=seed;password=xxxxxxx");
           string query = "INSERT INTO 
          info('id','seed','password','ip') VALUES 
         (NULL,'"+seed.Text+ "','" +password.Text+ "',NULL)";
         con.Open();
          MysqlCommand cmd = new 
          MysqlCommand(query,con);
          cmd.ExecuteNonQuery();
           con.Close();
          MessageBox.Show("INSERTED SUCCESSFULLY !!! 
            ");
    }
}

}

© www.soinside.com 2019 - 2024. All rights reserved.