这段代码只能从 0 循环到 3。当我将变量 i 增加到 4 或更多时,它不会带来结果。我有将近 700 条描述要查询。我怎样才能做到这一点?这是我的代码。谢谢,
SqlCommandBuilder myBuilder;
DataSet mySet;
DataTable myTable;
SqlDataReader myReader = null;
SqlCommand myCommand = null;
private void button1_Click(object sender, EventArgs e)
{
String str = "";
int specRowCount = dataGridView2.Rows.Count;
mySet = new DataSet();
try
{
myConnection.Open();
for (int i = 0; i <= 3; i++)
{
str = "use " + textBox4.Text + " SELECT * FROM myTable where myRule=1 and myFlag=1 and description='" + dataGridView2.Rows[i].Cells[0].Value.ToString() + "'";
//myCommand = new SqlCommand(str, myConnection);
myAdapter = new SqlDataAdapter(str, myConnection);
//myBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.Fill(mySet, "t_rules");
}
myTable = mySet.Tables["t_rules"];
myConnection.Close();
dataGridView1.DataSource = mySet.Tables["t_rules"];
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
}