richard smith

richard smith

  • 1.4k
  • 285
  • 160.7k

Add A Parameter to Query String populating Datagrid

Mar 25 2013 10:10 AM
I am using the below to populate a datagrid...works great. Now I want to add a parameter and am not sure how to.
I am working with this code to populate (Note this does not add a parameter like I want)
string SQLString = "Select * from tableInformation";
SqlDataAdapter dataAdapter = new SqlDataAdapter(SQLString, connectionString);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataTable table = new DataTable();
dataAdapter.Fill(table);
bsBindingSource1.DataSource = table
datagridview1.AutoResizeColumns(DataGridViewAutoSizeCOlumnsMode.AllCellsExceptHeader);
datagridview1.ReadOnly = true;
datagridview1.DataSource = bsBindingSource1;


Now how would I add a parameter to my SQL statement that is 
string SQLString = "SELECT * From tableInformation WHERE ZIP = @ZIP";

Parameters.AddWithValue("@Zip", "39281");

Answers (1)