How to insert,delete,select,update values in datagridview in C# using MYSQL

前端 未结 3 506
天涯浪人
天涯浪人 2021-01-07 05:20

Below is the code to insert value into mysql database, using datagridview. But the selectcommand is working.It is not happening since i get error stating \"Column \'username

相关标签:
3条回答
  • 2021-01-07 05:35

    Had a similar problem updating in mysql with datagrid (vb.net). Solved it with:

    Dim cmb As New MySqlCommandBuilder(datGrid)
    Me.datGrid.Update(datSet, "mysqlTableToUpdate")
    
    0 讨论(0)
  • 2021-01-07 05:39

    I am rather unsure, but doesn't mysql use numbered parameters with a "?"-synatx or named parameters with a ":"-syntax instead of (mssql) at-syntax ?

    Something like :

    MySqlCommand insertcommand = new MySqlCommand("insert into user(username,password) values(?, ?)", conn);
    insertcommand.Parameters.Add(1, MySqlDbType.VarChar,50,"username");
    insertcommand.Parameters.Add(2, MySqlDbType.VarChar, 50, "password");
    

    or

    MySqlCommand insertcommand = new MySqlCommand("insert into user(username,password) values(:username, :pass)", conn);
    insertcommand.Parameters.Add(":username", MySqlDbType.VarChar,50,"username");
    insertcommand.Parameters.Add(":pass", MySqlDbType.VarChar, 50, "password");
    
    0 讨论(0)
  • 2021-01-07 05:45

    I think you need to change the names of the parameters added to the insert command to match the names specified in the INSERT SQL statement.

    Try:

    insertcommand.Parameters.Add("@username",MySqlDbType.VarChar,50,"username");
    insertcommand.Parameters.Add("@password", MySqlDbType.VarChar, 50, "password");
    
    0 讨论(0)
提交回复
热议问题