locked
inserting problem in excel RRS feed

  • Question

  • User2031860760 posted
    i had copy a code from google to insert a record in excel i m mentioning my code below after dat i ll tell u d exception
    
    
    
     MySQLResumeSubmission db = new MySQLResumeSubmission();
            ExcelSheetGenerationDemo user = new ExcelSheetGenerationDemo();
    
            user.name = TextBox1.Text;
            user.fname = TextBox2.Text;
            user.add = TextBox3.Text;
    
            try
            {
                System.Data.OleDb.OleDbConnection MyConnection;
                System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
                string sql = null;
                MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\users.xls';Extended Properties=Excel 8.0;");
                MyConnection.Open();
                myCommand.Connection = MyConnection;
                sql = "Insert into users VALUES('1','2','3')";
                myCommand.CommandText = sql;
                myCommand.ExecuteNonQuery();
                MyConnection.Close();
            }
            catch (Exception ex)
            {
                Label1.Text = ex.ToString();
            }
    i have set my file name to users and kept it under C:/ Driveand plss tell me wat to write in datasource and wat to write in the query....where we mention
    like insert into ....(wat to write here) is the datasource file name and query file name are same or different....the exception i got is 
    System.Data.OleDb.OleDbException (0x80040E37): The Microsoft Jet database engine could not find the object 'users'. Make sure the object exists and that you spell its name and the path name correctly. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at TestInsertIntoExcel.Button1_Click(Object sender, EventArgs e) in c:\Documents and Settings\Tarun Verma\My Documents\Visual Studio 2010\WebSites\WebSite11\TestInsertIntoExcel.aspx.cs:line 33
    
    Tuesday, June 21, 2011 3:06 AM

All replies

  • User-269404413 posted

    Tarun,

    in this code

    "Insert into users VALUES('1','2','3')";

    users is your sheet name? if not then try to give the sheet name instead of users then it'll work.

    Tuesday, June 21, 2011 3:35 AM
  • User2031860760 posted

    i tried it bt still its giving same exception

    Tuesday, June 21, 2011 7:41 AM
  • User-1694870838 posted

    Hi,

    do you have checked you 'users' sheet?

    "Insert into users VALUES('1','2','3')"

    maybe users is Users.

    Best Regards,

     

    Wednesday, June 29, 2011 10:25 PM