public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string sname = this.textBox1.Text;
SqlConnection conn = new SqlConnection(@"Data Source=LAPTOP-HIUQTNAV;Initial Catalog=demo;Integrated Security=True");
string sql = string.Format("select sno,sname,sex,age,dept from dbo.student where sname like '%{0}%'",sname);
SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "student");
this.dataGridView1.DataSource =ds.Tables["student"];
}
private void button5_Click(object sender, EventArgs e)
{
}
private void Form6_Load(object sender, EventArgs e)
{
getdata();
}
public void getdata()
{
SqlConnection conn = new SqlConnection(@"Data Source=LAPTOP-HIUQTNAV;Initial Catalog=demo;Integrated Security=True");
string sql = string.Format("select sno,sname,sex,age,dept from dbo.student");
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "student");
this.dataGridView1.DataSource = ds.Tables["student"];
}
private void button2_Click(object sender, EventArgs e)
{
Form7 fr7 = new Form7();
fr7.Show();
}
using System;
using System.Collections.Generic;
using System.Component
列为空