private void Form2_Load(object sender, EventArgs e)
{
cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename="+@"D:\Documents and Settings\soft-2003\My Documents\myex.mdf"+";Integrated Security=True;Connect Timeout=30;User Instance=True");
string com = "select * from nihaoma";
ad = new SqlDataAdapter(com, cn);
cn.Open();
ad.Fill(data);
dataGrid1.DataSource = data;
cn.Close();
}
private void huanToolStripMenuItem_Click(object sender, EventArgs e)
{
string com = "select ni from nihaoma";
ad = new SqlDataAdapter(com, cn);
cn.Open();
data.Clear();//////清除所有的表
ad.Fill(data);
//dataGrid1.tables
dataGrid1.DataSource = data;//再重新定向 数据源
cn.Close();
}
决定人生~