Connect MySQL using C# (ODBC Connection)
//using System.Data.Odbc;
OdbcCommand ocmd;
OdbcDataAdapter da;
OdbcConnection dbcon = new OdbcConnection("DRIVER={MySQL ODBC 5.1 Driver};server=127.0.0.1;UID=admin;Password=admin;Persist Security Info=True;port=3308;Connection Reset=False;database=dbdata");
dbcon.Open();
da=new OdbcDataAdapter("SELECT * FROM `tblstudent` ORDER BY `Last_Name`,`First_Name`, `Middle_Name` ASC",dbcon);
ds = new DataSet();
da.Fill(ds,"tblstudent");
dbcon.Close();
MessageBox.Show(ds.Tables["tblstudent"].Rows[5].ItemArray[3].ToString());
// INSERT, UPDATE, DELETE
OdbcCommand ocmd;
OdbcDataAdapter da;
OdbcConnection dbcon = new OdbcConnection("DRIVER={MySQL ODBC 5.1 Driver};server=127.0.0.1;UID=admin;Password=admin;Persist Security Info=True;port=3308;Connection Reset=False;database=dbdata");
dbcon.Open();
ocmd=new OdbcCommand("INSERT INTO tblstudent (`Stud_ID`) VALUES('00-99999')",dbcon);
ocmd.ExecuteNonQuery();
dbcon.Close();
//using System.Data.Odbc;
OdbcCommand ocmd;
OdbcDataAdapter da;
OdbcConnection dbcon = new OdbcConnection("DRIVER={MySQL ODBC 5.1 Driver};server=127.0.0.1;UID=admin;Password=admin;Persist Security Info=True;port=3308;Connection Reset=False;database=dbdata");
dbcon.Open();
da=new OdbcDataAdapter("SELECT * FROM `tblstudent` ORDER BY `Last_Name`,`First_Name`, `Middle_Name` ASC",dbcon);
ds = new DataSet();
da.Fill(ds,"tblstudent");
dbcon.Close();
MessageBox.Show(ds.Tables["tblstudent"].Rows[5].ItemArray[3].ToString());
// INSERT, UPDATE, DELETE
OdbcCommand ocmd;
OdbcDataAdapter da;
OdbcConnection dbcon = new OdbcConnection("DRIVER={MySQL ODBC 5.1 Driver};server=127.0.0.1;UID=admin;Password=admin;Persist Security Info=True;port=3308;Connection Reset=False;database=dbdata");
dbcon.Open();
ocmd=new OdbcCommand("INSERT INTO tblstudent (`Stud_ID`) VALUES('00-99999')",dbcon);
ocmd.ExecuteNonQuery();
dbcon.Close();
0 comments:
Post a Comment