I am very surprised of the coding generate error message
Error 1 Use of unassigned local variable 'strSql'
even though the strSQL variable was declared. Not sure what is wrong with the overall coding;
Here are the coding:
Expand|Select|Wrap|Line Numbers
- private void FLoadDataGridView()
- {
- string strSql;
- if (this.radioBtnAll.Checked == true)
- {
- strSql = "Select * from Customers Order by CustomerID";
- }
- if (this.radioBtnSome.Checked == true)
- {
- strSql = "Select * from Customers ";
- strSql += "Where CustomerID like 'this.txtSome.Text%'";
- strSql += "Order by CustomerID ";
- }
- sqlConn = new SqlConnection(connStr);
- sqlConn.Open();
- DA = new SqlDataAdapter(strSql, sqlConn); <---- Error
- DS = new DataSet("DS");
- DA.Fill(DS,"Customer");
- dataGridView1.DataSource = DS.Tables["Customer"];
- dataGridView1.ClearSelection();
- sqlConn.Close();
- DS.Dispose();
- }
Thank You.
Cheers,
Lennie