In C# ... How can i search my access database by some column(other than the primary key).. for example if i want user to search entries by Entring last name in a textbox .. and this could have more than one entry and show the results in the grid view table ...???

You simply specify the columns name you want to seach by in the WHERE clause, and define it as parameter of the query:

DataTable table = new DataTable();
OdbcConnection conn = new OdbcConnection("connString");
string query = @"SELECT * FROM Person WHERE LastName = @last";
OdbcCommand cmd = new OdbcCommand(query, conn);
cmd.Parameters.Add("@last", SqlDbTyple.VarChar, 50).Value = textBox1.Text;
OdbcDataAdapter da = new OdbcDataAdapter(cmd);
da.Fill(table);

Now your table has all the rows from the table, based on the lastnames (the rows that have this name written in textbox

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.