Re: Insert into MySql Table
Quote:
Originally Posted by
Raidzen10
[...]
string com = "INSERT INTO Users(Name, Surname, Pass, Email, Type)
VALUES(@Name,@Surname,@Password,@Emailaddr, @type)";
MySqlCommand Com = new MySqlCommand(com, con);
Com.CommandType = CommandType.Text;
Com.Parameters.Add(new MySqlParameter("?Name", MySqlDbType.Text).Value = txtfname.Text);
[..]
First: I do believe you have a matter due to the use of the "@" parameter that mySql does not like.
In any case, you should be consistent with yourself : you used "?" in the parameters, and you should use it also in the query, like in the following example:
Code:
string theQuery = "INSERT INTO Users(Name, Surname, Pass, Email, Type)
VALUES(?Name,?Surname,?Password,?Emailaddr, ?type)";
Second:
you have some special names there:
Name
and expecially
Type
you should surround them in brackets : "[" and "]"
Code:
string theQuery = "INSERT INTO Users([Name], Surname, Pass, Email, [Type])
VALUES(?Name,?Surname,?Password,?Emailaddr, ?type)";
Third (less important, this is to make your life better, you can completely disregard the following)
c# is case sensitive, thus you might have a variable named "com" foro the commandString and a variable named "Com" for the Command Object. But let me suggest you to name one of the two in a different way