使用C#与xampp建立数据库连接

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

我使用xampp作为我的sql数据库服务器。

我试图连接到它,但它没有工作。

我是C#的新手

这是我的代码

namespace InventoryManagement
{
      public partial class Form1 : Form
      {
            public string dbconnect = "Server=127.0.0.1;User=root@localhost;password=;database=inventory;";

      }

      private void button3_Click(object sender, EventArgs e)
      {
           SqlConnection connect = new SqlConnection();
           connect.ConnectionString = dbconnect;
           connect.Open();

           if (connect.State == ConnectionState.Open)
           {
                 MessageBox.Show("connected");
           }
       }
}

任何帮助深表感谢。

谢谢。

c# database mysqli xampp
1个回答
0
投票

也许你应该试试这个

public string conn = "server=localhost; user id = root; database=inventory";
© www.soinside.com 2019 - 2024. All rights reserved.