添加查询结果

时间:2013-01-12 08:21:57

标签: datagridview listbox

我想将书表加载到DataGridView,如果bookname小于10个字符,请在ListBox

中添加

怎么做?

public partial class DataGridViewSample : Form  
{   
sqlconnection conn = new sqlconnection ("connection string");

DataTable dt = null;

private void LoadData(string vCommand)

    {
      if (vSqlConnection.State == ConnectionState.Closed)
      {  
        vSqlConnection.Open();

        using (SqlDataAdapter sda = new SqlDataAdapter(vCommand, conn))
        {
          sda.Fill(dt);
          dataGridView.DataSource = dt;
        }
        vSqlConnection.Close();
      }
    }

    private void button1_Click(object sender, EventArgs e)
    {
      string vCommand = @"Select * From Book";
      LoadData(vCommand);
    }
}

0 个答案:

没有答案