Syntax for inserting a record on a MySql database

May 11 2006 3:37 AM
I got this problem on inserting a record to a certain database.
The solution could be in converting values to be able to save the data on the database.
Please help me on this one.

I use the following codes:

string t1; string sc;
t1=Textbox1.Text;
sc=2;

string ConnStr="Driver={MySQL ODBC 3.51 Driver};" + "Server=localhost;Database=tic";
    OdbcConnection con=new OdbcConnection(ConnStr);
    OdbcCommand cmd=new OdbcCommand("SELECT * FROM player",con);
    con.Open();
    OdbcDataReader MyDataReader;
    MyDataReader=cmd.ExecuteReader();

    cmd.CommandText="INSERT INTO player(name,score) VALUES("+t1+","+sc+")";
    cmd.ExecuteNonQuery();

    MyDataReader.Close();
    con.Close();

whereas the value of t1 is 'lei' based from the value of Textbox1.
Error Message shows:

ERROR [42S21] [MySQL][ODBC 3.51 Driver][mysqld-4.0.16-nt]Unknown column 'lei' in 'field list'

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Odbc.OdbcException: ERROR [42S21] [MySQL][ODBC 3.51 Driver][mysqld-4.0.16-nt]Unknown column 'lei' in 'field list'



Answers (1)