Page 1 of 1

Inserting data into a table

Posted: Wed 07 Dec 2005 14:39
by AxCx
Hey all

Im trying to make a method where I can insert data into a table.

I have created a database called "csharp" and a table called "test"

So far my code looks like this:
public void Opdater()
{
MySqlConnection connection = new
MySqlConnection("host=localhost;database=csharp;user id=root; password=*******");

connection.Open();
try
{
MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM test", mySqlConnection1);

MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder(adapter);
DataTable table = new DataTable("test");
adapter.Fill(table);
table.Rows.Add(new object[3]{
textBox2.Text,
textBox3.Text,
textBox4.Text});
adapter.Update(table);
}
catch (Exception ex)
{

Console.WriteLine(ex.Message);
}
finally
{
mySqlConnection1.Close();
}
}
I get an error saying
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by, tlf) VALUES ('Jakob', 'Odense', 62621894)' at line 1
Everytime I run the program and fill in the textboxes.

Could someone alittle more skilled see where the problem is? :D

Thanks
AxCx

Posted: Wed 07 Dec 2005 16:37
by Serious
We cannot reproduce your problem.
Please specify table 'test' definition ('create table' statement).

Posted: Wed 07 Dec 2005 16:45
by AxCx
hey thanks for the response.

I hope this is what you wanted to see :D
http://www.jajo.midtfyn.net/db.jpg

Posted: Wed 07 Dec 2005 18:13
by Guest
Update:

If I change the database to another one called "stormtest" which have a table also called "stormtest" (also with 3 rows as the "test" table I was tryning to use) the program is working and it's possible to insert data into the table mmm weird :?

Posted: Wed 07 Dec 2005 18:38
by AxCx
Problem solved :oops:

Had something to do with the row name "navn" changed it to "name" and it's all working now.