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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tapan PatelRank #614 · 3.9K reputationPosted Sep 7, 2016, 6:37 AM EDT
Tapan PatelRank #614 · 3.9K reputationPosted Sep 7, 2016, 5:15 AM EDT
Joseph KRank #8,523 · 220 reputationPosted Sep 7, 2016, 5:35 AM EDT
Joseph KRank #8,523 · 220 reputationPosted Sep 7, 2016, 11:56 PM EDT
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();
}
}
}
}