hello everybody. i have a C# program that insert some data to a table in excell. Iam suppose to insert the data in the first empty row of the excel file. the problem arise when i manually delete a row in the table in excel, the next time i run the application that row is not filled up, instead the next row in the table is, as if the values in the previous row where still there even though i deleted them any idea. below is the insert method i wrote.
string strExcelFilename = "c:\\Capitals.xls";
OleDbConnection conn = new OleDbConnection @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=" + strExcelFilename + ";" + @"Extended Properties=" + Convert.ToChar(34).ToString() + @"Excel 8.0;" + Convert.ToChar(34).ToString());
try
{
conn.Open();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
string s = "broke";
Console.WriteLine(s);
}
System.Data.OleDb.OleDbCommand objCmd = new System.Data.OleDb.OleDbCommand();
objCmd.Connection = conn;
//
objCmd.CommandText = " update [Sheet1$] "+"insert into [Sheet1$] (ID,town,State,Region)" + " values ('berga', 'Yippe',1,2)";
try
{
objCmd.ExecuteNonQuery();
//
}
catch(Exception error)
{
Console.WriteLine .(error.StackTrace);
Console.WriteLine(error.Message);
}
conn.Close();