Hii !!
I try to update excel file by using Odbc and Oledb objects
with out success.
my problem when i try to update string in cell that the Odbc "think" this cell is have different datatype.
how can i force the Object to put string at cell that have different datatype, or how can i make the object to not "guess " the datatype
i write 2 function that connect to mlay_List.xls
and do some query.
thank's for any help...
this is my code....
public Boolean UpDateExcl_ODBC(string Q)
{
OdbcConnection Con = null;
try
{
string FileName = @"Mlay_List.xls";
string ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" + FileName + ";DefaultDir=" + Application.StartupPath + ";Readonly=0;IMEX=1;HDR=Yes;ImportMixedTypes=Text;";
Con = new OdbcConnection(ConnectionString);
OdbcCommand cmd = new OdbcCommand(Q);
cmd.Connection = Con;
Con.Open();
cmd.ExecuteNonQuery();
Con.Close();
return true;
}
catch (Exception ex)
{
try { Con.Close(); }
catch { }
return false;
}
}
public Boolean UpDateExcl_OleDb(string Q)
{
OleDbConnection conn = null;
try
{
string FileName = @"Mlay_List.xls";
string connstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + FileName + ";Mode=ReadWrite;Extended Properties=\"Excel 8.0;HDR=YES;ReadOnly=0;\"";
//connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + ";Mode=ReadWrite;ReadOnly=false;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
conn = new OleDbConnection(connstr);
OleDbCommand cmd = new OleDbCommand(Q, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
return true;
}
catch (Exception EX)
{
conn.Close();
return false;
}
}