调试代码时会出现错误(调试前不会显示任何错误),下面是我在VisualStudio2017中使用C#编写的代码
using MySql.Data;
using MySql.Data.MySqlClient;
namespace MARUBI
{
public partial class addUser : Form
{
MySqlConnection con;
MySqlDataAdapter da;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
public addUser()
{
InitializeComponent();
string str = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\MARUBI\MARUBI\MARUBI\MarubiDB.mdf;Integrated Security=True;Connect Timeout=30";
con = new MySqlConnection(str);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string username = textBox1.Text;
string password = textBox2.Text;
string name = textBox3.Text;
string surename = textBox4.Text;
string tel = textBox5.Text;
string email = textBox6.Text;
string sql = "INSERT INTO dbo.users(username, password, name, surename, tel, email) VALUES ('"+username+"', '"+password+"','"+name+"','"+surename+"','"+tel+"','"+email+"'";
try
{
con.Open();
da = new MySqlDataAdapter();
da.InsertCommand = new MySqlCommand(sql, con);
da.InsertCommand.ExecuteNonQuery();
MessageBox.Show("Values inserted succesfully");
load_grid();
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void load_grid()
{
dt.Clear();
MySqlDataAdapter da = new MySqlDataAdapter();
try
{
string sql = "SELECT * FROM USERS";
con.Open();
da.SelectCommand = new MySqlCommand(sql, con);
da.Fill(ds);
da.Fill(dt);
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void addUser_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'marubiDBDUSERS.users' table. You can move, or remove it, as needed.
load_grid();
}
}这是我的代码,我得到了错误
System.ArgumentException:“不支持选项。 参数名称: attachdbfilename‘
发布于 2018-12-08 12:57:38
C#代码使用MySQL驱动程序:
MySqlConnection con;
MySqlDataAdapter da; 但是,您传递的连接字符串与竞争对手供应商(Microsoft SQL Server)的数据库系统完全不同:
"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\MARUBI\MARUBI\MARUBI\MarubiDB.mdf"要么使用正确的代码,要么使用正确的连接字符串;您没有说明实际使用的是哪个数据库
https://stackoverflow.com/questions/53681868
复制相似问题