#region InsertData in mdbFile
public void InserData()
{
OleDbConnection oledbConn = new OleDbConnection(); //D:\AAA
OleDbConnection oledbConn1 = new OleDbConnection();
try
{
oledbConn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
Application.StartupPath + @"\ExcelData\Hamid.mdb;Persist Security Info=False;");
var file = new FileInfo(@"D:\Hamid\Projects\HDA\Source Code\Working\HDA - V3\HydrologicalDesignAids\bin\Release\ExcelData\Hamid.mdb");
var to = @"D:\\AAA\";
if (!Directory.Exists(to))
{
Directory.CreateDirectory(to);
}
string strNewName = "NewHamidTest" + ".mdb";
string newName = to + strNewName;
// Rename file and Move at your specified Location .
string newPath = Path.Combine(to, newName);
file.CopyTo(newPath);
oledbConn1 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
newName + @";Persist Security Info=False;");
if (oledbConn.State == ConnectionState.Closed)
{
oledbConn.Open();
}
if (oledbConn1.State == ConnectionState.Closed)
{
oledbConn1.Open();
}
OleDbCommand cmd = new OleDbCommand();
var cmdText1 = "INSERT INTO ZoneDescription ([ZoneID]) VALUES( " + 45 + ")";
var command1 = new OleDbCommand(cmdText1, oledbConn1);
command1.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
oledbConn.Close();
oledbConn1.Close();
}
}
#endregion
public void InserData()
{
OleDbConnection oledbConn = new OleDbConnection(); //D:\AAA
OleDbConnection oledbConn1 = new OleDbConnection();
try
{
oledbConn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
Application.StartupPath + @"\ExcelData\Hamid.mdb;Persist Security Info=False;");
var file = new FileInfo(@"D:\Hamid\Projects\HDA\Source Code\Working\HDA - V3\HydrologicalDesignAids\bin\Release\ExcelData\Hamid.mdb");
var to = @"D:\\AAA\";
if (!Directory.Exists(to))
{
Directory.CreateDirectory(to);
}
string strNewName = "NewHamidTest" + ".mdb";
string newName = to + strNewName;
// Rename file and Move at your specified Location .
string newPath = Path.Combine(to, newName);
file.CopyTo(newPath);
oledbConn1 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
newName + @";Persist Security Info=False;");
if (oledbConn.State == ConnectionState.Closed)
{
oledbConn.Open();
}
if (oledbConn1.State == ConnectionState.Closed)
{
oledbConn1.Open();
}
OleDbCommand cmd = new OleDbCommand();
var cmdText1 = "INSERT INTO ZoneDescription ([ZoneID]) VALUES( " + 45 + ")";
var command1 = new OleDbCommand(cmdText1, oledbConn1);
command1.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
oledbConn.Close();
oledbConn1.Close();
}
}
#endregion
No comments:
Post a Comment