private void button1_Click(object sender, System.EventArgs e)
{
try
{
string StrSQL="SELECT * FROM wj WHERE ChineseName LIKE '";
StrSQL+=this.textBox1.Text+"'";
//if(this.comboBox1.Text=="All")
//StrSQL="SELECT * FROM wj";
this.sqlDataAdapter1.SelectCommand.CommandText=StrSQL;
this.sqlDataAdapter1.SelectCommand.Connection=this.sqlConnection1;
//打开数据库连接
this.sqlConnection1.Open();
//执行SQL命令
this.sqlDataAdapter1.SelectCommand.ExecuteNonQuery();
System.Data.SqlClient.SqlDataReader MyReader=this.sqlDataAdapter1.SelectCommand.ExecuteReader();
this.listView1.Clear();
this.listView1.View=View.Details;
for(int i=0;i<MyReader.FieldCount-1;i++)
{
this.listView1.Columns.Add(MyReader.GetName(i),100,HorizontalAlignment.Left);
}
while(MyReader.Read())
{
ListViewItem MyItem=new ListViewItem();
MyItem.Text=MyReader.GetString(3);
for(int j=0;j<MyReader.FieldCount-2;j++)
MyItem.SubItems.Add(MyReader.GetString(j+1));
this.listView1.Items.Add(MyItem);
}
//关闭连接
this.sqlConnection1.Close();
}
catch(Exception Err)
{
MessageBox.Show("查询数据库记录操作失败:"+Err.Message,"信息提示",
MessageBoxButtons.OK,MessageBoxIcon.Information);
//如果打开了连接,则关闭它
if(this.sqlConnection1.State==ConnectionState.Open)
{
this.sqlConnection1.Close();
}
}
}
请问我如何可以控制显示的字段,要在哪里改动呢?