Search This Blog

2010/01/17

MYSQL 5 & C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace Mysql2
{
class Program
{
static void Main(string[] args)
{
MySqlConnection con = new MySqlConnection("datasource=localhost;username=root;password=indusstar;database=mysql");
con.Open();

MySqlDataAdapter da = new MySqlDataAdapter("select * from courses", con);
//need table with rimary key
MySqlCommandBuilder cmdBuilder = new MySqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "courses");

DataRow drow = ds.Tables[0].NewRow();
drow[0] = 4;
drow[1] = "Gambas";
drow[2] = 3;
drow[3] = 5000;

ds.Tables[0].Rows.Add(drow);
da.Update(ds, "courses");

con.Close();

}
}
}

No comments:

Post a Comment