I want to write same c# code for inserting data and selecting data for ms-acess database and mysql database with same database structure.Is there any way?Please help me out.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tapan PatelPosted Sep 7, 2016, 10:37 AM
Joseph KPosted Sep 8, 2016, 3:56 AM
String conn = "server=localhost; database=sample; uid=root; password=somepassword";
using (MySqlConnection mysqlconn = new MySqlConnection(conn))
{
string query = "INSERT INTO Name VALUES(" + Name + ")";
using (MySqlCommand cmd = new MySqlCommand(query, mysqlconn))
{
try
{
mysqlconn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception)
{
}
finally
{
mysqlconn.Close();
mysqlconn.Dispose();
}
}
}
if (dataBase1 == "Ms Ascess")
{
String conn1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "sample.mdb;Jet OLEDB:Database Password=somepassword";
using (OleDbConnection oledbconn = new OleDbConnection(conn1))
{
string query = "INSERT INTO Name VALUES(" + Name + ")";
using (OleDbCommand cmd = new OleDbCommand(query, oledbconn))
{
try
{
oledbconn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception)
{
}
finally
{
oledbconn.Close();
oledbconn.Dispose();
}
}
}
}
Joseph KPosted Sep 7, 2016, 9:35 AM
Tapan PatelPosted Sep 7, 2016, 9:15 AM