Home > Net >  OLEDB is used to derive the datatable to MDB files, some lost
OLEDB is used to derive the datatable to MDB files, some lost

Time:04-20



This is the data in the datagridview

This is export MDB file, you can see the red box in the figure above lines,

I don't know what circumstance can appear this problem, but not every export has a problem, ask bosses help have a look, thanks a lot,
Use the code:
 private void datatableToMdb (string FileFullName) 
{
//Import the datatable into the table in the MDB file
String strCon="Provider=Microsoft. Ace. The OLEDB. 12.0; Data Source="+ FileFullName;
OleDbConnection myConn=new OleDbConnection (strCon);
MyConn. The Open ();
Try
{
String name="TS_Tags";//table name
String SQL="create table" + name;
String tableAttribute="";
The DataTable dt=clsGVar. DtTag;//the name of the datatable
for (int i=0; I & lt; Dt. Columns. The Count; I++)
{
TableAttribute=tableAttribute + dt. The Columns [I] ColumnName + "" + getType (dt) Columns [I] DataType. The ToString ());
If (I & lt; Dt. Columns. The Count - 1)
{
TableAttribute +=", ";
}
}
SQL=SQL + "(" + tableAttribute +"); ";
OleDbCommand CMD=new OleDbCommand (SQL, myConn);
CMD. ExecuteNonQuery ();
String strCom=the string. Format (" select * from {0} ", name);
OleDbDataAdapter da=new OleDbDataAdapter (strCom myConn);
OleDbCommandBuilder cb=new OleDbCommandBuilder (da)
{
QuotePrefix="[",
QuoteSuffix="] "
};
The DataSet midData=https://bbs.csdn.net/topics/new DataSet ();
Da. The Fill (midData, name);
Foreach (DataRow dR in dt. Rows)
{
DataRow Dr=midData. Tables [name] NewRow ();
Dr. ItemArray=Dr. ItemArray;
MidData. Tables [name]. Rows. The Add (Dr);
}
Da. Update (midData, name);
MyConn. Close ();
}
The catch (Exception ex)
{
Ex. The ToString ();
}
The finally
{
MyConn. Close ();
}
}
  •  Tags:  
  • C#
  • Related