Page 1 of 1
					
				Syntax for Insert into Table
				Posted: Thu  14 Apr 2005 01:22
				by adebayo
				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
			 
			
					
				
				Posted: Thu  14 Apr 2005 07:28
				by Serious
				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();
      }
 
			 
			
					
				
				Posted: Thu  14 Apr 2005 20:56
				by adebayo
				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.
			 
			
					
				
				Posted: Mon  18 Apr 2005 08:18
				by Serious
				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.