Syntax for Insert into Table

Syntax for Insert into Table

Postby adebayo » Thu 14 Apr 2005 01:22

Hello

I have just installed the MySQLDirect.net on my machine. I am currently writing an pplication in c#. I know the syntax for inserting records into a table, but I am wondering if there is a specific way of doing it, if I am connected via mySQLDirect.net. The code that I have written is not working. Please help me.

Ade
adebayo
 
Posts: 2
Joined: Thu 14 Apr 2005 01:16

Postby Serious » Thu 14 Apr 2005 07:28

You can use MySqlCommandBuilder component. MySqlCommandBuilder provides a means of automatically generating single-table commands used to reconcile changes made to a DataSet or DataTable with the associated MySQL server database.
Code: Select all
      MySqlConnection connection  = new MySqlConnection("host=localhost;database=test;user id=root");
      connection.Open();
      try
      {
        MySqlDataAdapter adapter = new MySqlDataAdapter("select * from dept", connection);
        MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder(adapter);
        DataTable table = new DataTable("dept");
        adapter.Fill(table);
        // insert, update, delete rows here
        table.Rows.Add(new object[] {1000,"a","b"});

        adapter.Update(table);
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
      finally
      {
        connection.Close();
      }
Last edited by Serious on Mon 18 Apr 2005 07:30, edited 1 time in total.
Serious
 

Postby adebayo » Thu 14 Apr 2005 20:56

Thanks for the reply. I have implemented your solution and it is almost working. I now have a minor problem, the problem is that when I fill the form with data, the actual field name gets written to the database instead of the values completed. How do I get the real value of the form fields.
adebayo
 
Posts: 2
Joined: Thu 14 Apr 2005 01:16

Postby Serious » Mon 18 Apr 2005 08:18

Once you have filled DataSet or DataTable with database data, you can bind this data to form controls in common ways. You can find all information you need about data binding in MSDN. There are also demo projects in MySQLDirect .NET installation package.
Serious
 


Return to dotConnect for MySQL