我想将书表加载到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);
}
}