Click here to Skip to main content
16,016,290 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my code is as follow:
C#
private DataTable GetData()
    {
        DataTable dt = new DataTable();
        string connection_string = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\HILProject\project4\App_Data\adminlog.mdb";
        using (OleDbConnection cn = new OleDbConnection(connection_string))

        using (OleDbDataAdapter adp = new OleDbDataAdapter("select Name,Email_Id, Mob_No, Dob From UserReg ", cn))
        using (OleDbCommand command = new OleDbCommand()) 
        {
            cn.Open();
          adp.Fill(dt);
        }
        return dt;
    }
}


i want to retrieve data by using "where username = Textbox1.text"
username is a column name of table userreg
how to write where clause
Posted
Updated 1-Jun-14 5:05am
v2

 
Share this answer
 
C#
string queryString ="select Name,Email_Id, Mob_No, Dob From UserReg where username =?";
using (OleDbConnection connection =
           new OleDbConnection(connectionString))
{
    OleDbDataAdapter adapter =
        new OleDbDataAdapter(queryString, connection);

    // Set the parameters.
    adapter.SelectCommand.Parameters.AddWithValue("@p1", Textbox1.Text);

    // Open the connection and fill the DataSet.
    try
    {
        connection.Open();
        adapter.Fill(dt);
    }
    catch (Exception ex)
    {
        //Console.WriteLine(ex.Message);
    }
    // The connection is automatically closed when the
    // code exits the using block.
}
return dt;


Reference:OleDbParameter Class[^]
 
Share this answer
 
v2
Comments
Ashwini Thakare 1-Jun-14 11:27am    
thank you
DamithSL 1-Jun-14 11:33am    
you are welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900