locked
datatype of autonumber of access RRS feed

  • Question

  • User383567333 posted

    I have access database with column "nID(autonumber)"  , i want to delete record using it in grid view like this


    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string Id = GridView2.DataKeys[e.RowIndex].Values[0].ToString();
            con.Open();
            OleDbCommand cmd = new OleDbCommand("delete * from add_property where nID = '" + Id + "'", con);
            cmd.ExecuteNonQuery();
            GridView2.EditIndex = -1;
            con.Close();
            bindx();
        }

    so plz tell me what to define datatype of this field, i alway getting error when i define it Int32


    Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.


    Thanks


    Wednesday, June 9, 2010 3:45 AM

Answers

  • User187056398 posted

    When this line is done:  ...("delete * from add_property where nID = '" + Id + "'

    It will look something like:   delete * from add_property where nID = '123'

    Use '' for text only, for numbers you don't need them, you want:

        delete * from add_property where nID = 123

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 9, 2010 6:59 AM

All replies

  • User187056398 posted

    When this line is done:  ...("delete * from add_property where nID = '" + Id + "'

    It will look something like:   delete * from add_property where nID = '123'

    Use '' for text only, for numbers you don't need them, you want:

        delete * from add_property where nID = 123

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 9, 2010 6:59 AM
  • User383567333 posted


            string Id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
            con.Open();
            OleDbCommand cmd = new OleDbCommand("delete * from enquiry where nID = " + Id , con);
            cmd.ExecuteNonQuery();


    as per your valuable advice i made change ,but still it is not working my problem is here nID is autonumber and passing Id is string , so tell me how could i manage it....


    Thanks


    Wednesday, June 9, 2010 7:53 AM
  • User-1199946673 posted

    still it is not working my problem is here nID is autonumber and passing Id is string , so tell me how could i manage it....

     

    This should work, however you better use parameterized queries:

    http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access

    But when you specify a delete command in your datasource, add ID to the deleteparameters collection this shoudl work without a single line of code behind! Show us your HTML markup?

    Wednesday, June 9, 2010 8:38 AM