public void ShowDialog(string opendetails, IWin32Window parent)
{
SqlConnection conn = new SqlConnection( "Data Source=.\\sqlexpress;Initial Catalog=hardware;Integrated Security=True");
string sqlString = string.Format("SELECT {0} FROM dexceptional", opendetails);
SqlCommand cmd1 = new SqlCommand(sqlString, conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd1);
SqlCommandBuilder cmdBuilder1 = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet();
DataTable table = new DataTable(); conn.Open(); adapter.Fill(table); BindingSource bindingSource2 = new BindingSource();
bindingSource2.DataSource = table; this.dataGridView1.DataSource = bindingSource2;
bindingNavigator1.BindingSource = bindingSource2; this.ShowDialog(parent);
} private void toolStripButton1_Click(object sender, EventArgs e)
{
这里如何调用 bindingsource2 和adapter
this.Validate();
this.bindingSource2.Endedit(); 不行
this.adapter.Update(table); 不行
}
{
SqlConnection conn = new SqlConnection( "Data Source=.\\sqlexpress;Initial Catalog=hardware;Integrated Security=True");
string sqlString = string.Format("SELECT {0} FROM dexceptional", opendetails);
SqlCommand cmd1 = new SqlCommand(sqlString, conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd1);
SqlCommandBuilder cmdBuilder1 = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet();
DataTable table = new DataTable(); conn.Open(); adapter.Fill(table); BindingSource bindingSource2 = new BindingSource();
bindingSource2.DataSource = table; this.dataGridView1.DataSource = bindingSource2;
bindingNavigator1.BindingSource = bindingSource2; this.ShowDialog(parent);
} private void toolStripButton1_Click(object sender, EventArgs e)
{
这里如何调用 bindingsource2 和adapter
this.Validate();
this.bindingSource2.Endedit(); 不行
this.adapter.Update(table); 不行
}
SqlDataAdapter adapter ;写成全局变量
,最好是在类头就声明一个空的 bindingsource2 和adapter
把这个DataSet ds = new DataSet();
DataTable table = new DataTable();
写在方法外面,搞成全局的.
建议有空多看看上学时候的书.
BindingSource bindingSource2 ;
DataTable table ;
public void ShowDialog(string opendetails, IWin32Window parent)
{
SqlConnection conn = new SqlConnection( "Data Source=.\\sqlexpress;Initial Catalog=hardware;Integrated Security=True");
string sqlString = string.Format("SELECT {0} FROM dexceptional", opendetails);
SqlCommand cmd1 = new SqlCommand(sqlString, conn);
adapter = new SqlDataAdapter(cmd1);
SqlCommandBuilder cmdBuilder1 = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet();
table = new DataTable(); conn.Open(); adapter.Fill(table); bindingSource2 = new BindingSource();
bindingSource2.DataSource = table; this.dataGridView1.DataSource = bindingSource2;
bindingNavigator1.BindingSource = bindingSource2; this.ShowDialog(parent);
} private void toolStripButton1_Click(object sender, EventArgs e)
{
这里如何调用 bindingsource2 和adapter this.Validate();
bindingSource2.Endedit(); //可以
adapter.Update(table); //可以 table也要作为全局变量.
}
BindingSource bindingSource2=new BindingSource();
DataTable table = new DataTable();
把用到的定义成全局变量。
DataSet ds ;
DataTable table;