1
Answer

Add A Parameter to Query String populating Datagrid

richard smith

richard smith

11y
1.7k
1
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)