No value given for one or more required parameters RRS feed

  • Question

  • Hi,

    I have created a database for Employee datails in MS Access.And I m using GridView for diaplaying the Database contents in the form.
    To delete a particular selceted data of gridview from database, i m using the above code.


    string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\AT-FCT\\From_ShivaPriya\\AcousticTransmitter_29July10\\ATFCT_DB.accdb";


    OleDbConnection ATFCTconnection = new OleDbConnection(connectionString);



    OleDbCommand ATFCTCommand = new OleDbCommand();

    ATFCTCommand.Connection = ATFCTconnection;


    int i = dataGridView1.SelectedCells[0].RowIndex;


    string username = dataGridView1.Rows[i].Cells[0].Value.ToString();


    string query = "DELETE from UserManagement where Username =" + username;

    ATFCTCommand.CommandText = query;







    But the code is giving "No value given for one or more requiired parameters"


    Pls help me in cornering the issue.

    Thanks in advance :)

    Monday, August 2, 2010 11:58 AM


  • If Username field is defined is table as string then you need to inclose all the items you pass in your SQL statement into single quotes, something like

    string query = "DELETE from UserManagement where Username ='" + username +"'";

    But better way would be to pass all the values as parameters and provider will take care of it, for example

    string query = "DELETE from UserManagement where Username = ?"

    Then pass value as OledbParameter in your command

    Val Mazur (MVP) http://www.xporttools.net
    Monday, August 2, 2010 12:55 PM