Inserting data into a table

Inserting data into a table

Postby AxCx » Wed 07 Dec 2005 14:39

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
AxCx
 

Postby Serious » Wed 07 Dec 2005 16:37

We cannot reproduce your problem.
Please specify table 'test' definition ('create table' statement).
Serious
 

Postby AxCx » Wed 07 Dec 2005 16:45

hey thanks for the response.

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

Postby Guest » Wed 07 Dec 2005 18:13

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 :?
Guest
 

Postby AxCx » Wed 07 Dec 2005 18:38

Problem solved :oops:

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


Return to dotConnect for MySQL