问题描述
namespaceSoccerVIP{publicpartialclassForm2:Form{DataSetmyDataSet;//存放从数据库取来的数据的。OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接OleDbDataAdaptermyDataAdapter;//用来执行SQL命令publicForm2(){InitializeComponent();}publicvoidRefreshDG(){if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}stringsql="select*fromSoccerClub";myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidForm2_Load(objectsender,EventArgse){comboBox1.Items.Clear();comboBox1.Items.Add("tID");comboBox1.Items.Add("firstname");comboBox1.Items.Add("lastname");comboBox1.Items.Add("tel");comboBox1.Items.Add("address");comboBox1.Items.Add("favoriteTeam");comboBox1.Items.Add("rentTime");comboBox1.Items.Add("coach");try{stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";myOleConn=newOleDbConnection(ConStr);myOleConn.Open();myDataSet=newDataSet();RefreshDG();}catch{MessageBox.Show("连接数据库有问题,未连接成功。");}}privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){comboBox2.Items.Clear();comboBox2.Items.Add("=");if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){comboBox2.Items.Add(">");comboBox2.Items.Add(">=");comboBox2.Items.Add("<");comboBox2.Items.Add("<=");}}privatevoidbutton1_Click(objectsender,EventArgse){if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text=="")){MessageBox.Show("查询条件不能为空");return;}stringsql="select*fromSoccerClubwhere";stringstr="";if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){str=comboBox1.Text+comboBox2.Text+textBox1.Text;}else{str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";}sql+=str;if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){System.Diagnostics.Process.Start(linkLabel1.Text);}privatevoidlabel1_Click(objectsender,EventArgse){}}}
解决方案
解决方案二:
namespaceSoccerVIP{publicpartialclassForm2:Form{DataSetmyDataSet;//存放从数据库取来的数据的。OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接OleDbDataAdaptermyDataAdapter;//用来执行SQL命令publicForm2(){InitializeComponent();}publicvoidRefreshDG(){//移除旧的数据if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}//读取所有的SocerClub数据,并绑定到dataGridView1上stringsql="select*fromSoccerClub";myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidForm2_Load(objectsender,EventArgse){comboBox1.Items.Clear();comboBox1.Items.Add("tID");comboBox1.Items.Add("firstname");comboBox1.Items.Add("lastname");comboBox1.Items.Add("tel");comboBox1.Items.Add("address");comboBox1.Items.Add("favoriteTeam");comboBox1.Items.Add("rentTime");comboBox1.Items.Add("coach");try{//链接数据库stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";myOleConn=newOleDbConnection(ConStr);myOleConn.Open();//读取数据myDataSet=newDataSet();RefreshDG();}catch{MessageBox.Show("连接数据库有问题,未连接成功。");}}privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){comboBox2.Items.Clear();comboBox2.Items.Add("=");if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){comboBox2.Items.Add(">");comboBox2.Items.Add(">=");comboBox2.Items.Add("<");comboBox2.Items.Add("<=");}}privatevoidbutton1_Click(objectsender,EventArgse){if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text=="")){MessageBox.Show("查询条件不能为空");return;}stringsql="select*fromSoccerClubwhere";stringstr="";if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){str=comboBox1.Text+comboBox2.Text+textBox1.Text;}else{str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";}sql+=str;if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}//根据条件查询myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){//打开某个链接System.Diagnostics.Process.Start(linkLabel1.Text);}privatevoidlabel1_Click(objectsender,EventArgse){}}}
解决方案三:
拜托细致点呗,我们课程设计,实在不会啊
解决方案四:
haha
解决方案五:
我都愁死了,别haha了。。。
解决方案六:
//namespaceSoccerVIP//{//publicpartialclassForm2:Form//{//DataSetmyDataSet;//存放从数据库取来的数据的。//OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接//OleDbDataAdaptermyDataAdapter;//用来执行SQL命令//publicForm2()//{//InitializeComponent();//}//publicvoidRefreshDG()//{//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//stringsql="select*fromSoccerClub";//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidForm2_Load(objectsender,EventArgse)//{//comboBox1.Items.Clear();//comboBox1.Items.Add("tID");//comboBox1.Items.Add("firstname");//comboBox1.Items.Add("lastname");//comboBox1.Items.Add("tel");//comboBox1.Items.Add("address");//comboBox1.Items.Add("favoriteTeam");//comboBox1.Items.Add("rentTime");//comboBox1.Items.Add("coach");//try//{//stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="//+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";//myOleConn=newOleDbConnection(ConStr);//myOleConn.Open();//myDataSet=newDataSet();//RefreshDG();//}//catch//{//MessageBox.Show("连接数据库有问题,未连接成功。");//}//}//privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)//{//comboBox2.Items.Clear();//comboBox2.Items.Add("=");//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//comboBox2.Items.Add(">");//comboBox2.Items.Add(">=");//comboBox2.Items.Add("<");//comboBox2.Items.Add("<=");//}//}//privatevoidbutton1_Click(objectsender,EventArgse)//{//if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text==""))//{//MessageBox.Show("查询条件不能为空");//return;//}//stringsql="select*fromSoccerClubwhere";//stringstr="";//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//str=comboBox1.Text+comboBox2.Text+textBox1.Text;//}//else//{//str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";//}//sql+=str;//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse)//{//System.Diagnostics.Process.Start(linkLabel1.Text);//}//privatevoidlabel1_Click(objectsender,EventArgse)//{//}//}//}
全部帮你注释了。
解决方案七:
解决方案八:
namespaceSoccerVIP{publicpartialclassForm2:Form{DataSetmyDataSet;//存放从数据库取来的数据的。OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接OleDbDataAdaptermyDataAdapter;//用来执行SQL命令publicForm2(){InitializeComponent();}//方法用来判断myDataSet里面是否包含"SoccerClub"是就移除,下面就是绑定数据了SoccerClub表里的数据绑定到dataGridView1中publicvoidRefreshDG(){if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}stringsql="select*fromSoccerClub";myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}//这是form2窗体加载时候comboBox1控件加载itemprivatevoidForm2_Load(objectsender,EventArgse){comboBox1.Items.Clear();comboBox1.Items.Add("tID");comboBox1.Items.Add("firstname");comboBox1.Items.Add("lastname");comboBox1.Items.Add("tel");comboBox1.Items.Add("address");comboBox1.Items.Add("favoriteTeam");comboBox1.Items.Add("rentTime");comboBox1.Items.Add("coach");//链接数据库语句,下面有异常就捕获try{stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";myOleConn=newOleDbConnection(ConStr);myOleConn.Open();myDataSet=newDataSet();RefreshDG();}catch{MessageBox.Show("连接数据库有问题,未连接成功。");}}//这里是触发comboBox1的SelectedIndexChanged事件,判断选择的是哪个,有对应的操作privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){comboBox2.Items.Clear();comboBox2.Items.Add("=");if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){comboBox2.Items.Add(">");comboBox2.Items.Add(">=");comboBox2.Items.Add("<");comboBox2.Items.Add("<=");}}//这个是button1的点击事件,判断输入,接下来就是sql语句选择你comboBox选中的条件进行数据绑定再显示在dataGridView1控件中privatevoidbutton1_Click(objectsender,EventArgse){if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text=="")){MessageBox.Show("查询条件不能为空");return;}stringsql="select*fromSoccerClubwhere";stringstr="";if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){str=comboBox1.Text+comboBox2.Text+textBox1.Text;}else{str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";}sql+=str;if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}//这个是点击linkLabel1控件触发的事件启动进程privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){System.Diagnostics.Process.Start(linkLabel1.Text);}//这个估计是你自己点了label1控件才多出来的privatevoidlabel1_Click(objectsender,EventArgse){}}}新年第一天帮你注释下
解决方案九:
愁啥,来一把DOTA接千愁,啥,不行,那再来一把LOL~哦也,就是这个
解决方案十:
来这里叫别人帮做作业,你家人知道吗
解决方案十一:
引用9楼hwenycocodq520的回复:
来这里叫别人帮做作业,你家人知道吗
解决方案十二:
publicForm2(){InitializeComponent();}publicvoidRefreshDG(){//判断dataset里面是否包含了SoccerClub表名,存在则删除否则下面查询出来追加if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}stringsql="select*fromSoccerClub";myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//执行查询myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//查出的数据绑定GridView}//窗体初始化加载combox1数据。privatevoidForm2_Load(objectsender,EventArgse){comboBox1.Items.Clear();comboBox1.Items.Add("tID");comboBox1.Items.Add("firstname");comboBox1.Items.Add("lastname");comboBox1.Items.Add("tel");comboBox1.Items.Add("address");comboBox1.Items.Add("favoriteTeam");comboBox1.Items.Add("rentTime");comboBox1.Items.Add("coach");try{//连接数据字符串stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";myOleConn=newOleDbConnection(ConStr);myOleConn.Open();myDataSet=newDataSet();RefreshDG();//绑定数据}catch{MessageBox.Show("连接数据库有问题,未连接成功。");}}//combox选择事件privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){comboBox2.Items.Clear();comboBox2.Items.Add("=");//一些判断if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){//上面清除combox后在追加进去comboBox2.Items.Add(">");comboBox2.Items.Add(">=");comboBox2.Items.Add("<");comboBox2.Items.Add("<=");}}//button事件privatevoidbutton1_Click(objectsender,EventArgse){//判断条件是否为空if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text=="")){MessageBox.Show("查询条件不能为空");return;}//sql数据stringsql="select*fromSoccerClubwhere";stringstr="";if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){//查询条件str=comboBox1.Text+comboBox2.Text+textBox1.Text;}else{//查询条件str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";}sql+=str;//拼接sql//判断dataset里面是否包含了SoccerClub表名,存在则删除否则下面查询出来追加if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//执行查询myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//查出的数据绑定GridView}//执行打开文本事件privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){System.Diagnostics.Process.Start(linkLabel1.Text);}privatevoidlabel1_Click(objectsender,EventArgse){}}
解决方案十三:
尼玛,这块赶上百度知道了,什么问题的都有!
解决方案十四:
又是一个平时不好好学习的孩子
解决方案十五:
引用5楼shencb的回复:
//namespaceSoccerVIP//{//publicpartialclassForm2:Form//{//DataSetmyDataSet;//存放从数据库取来的数据的。//OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接//OleDbDataAdaptermyDataAdapter;//用来执行SQL命令//publicForm2()//{//InitializeComponent();//}//publicvoidRefreshDG()//{//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//stringsql="select*fromSoccerClub";//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidForm2_Load(objectsender,EventArgse)//{//comboBox1.Items.Clear();//comboBox1.Items.Add("tID");//comboBox1.Items.Add("firstname");//comboBox1.Items.Add("lastname");//comboBox1.Items.Add("tel");//comboBox1.Items.Add("address");//comboBox1.Items.Add("favoriteTeam");//comboBox1.Items.Add("rentTime");//comboBox1.Items.Add("coach");//try//{//stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="//+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";//myOleConn=newOleDbConnection(ConStr);//myOleConn.Open();//myDataSet=newDataSet();//RefreshDG();//}//catch//{//MessageBox.Show("连接数据库有问题,未连接成功。");//}//}//privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)//{//comboBox2.Items.Clear();//comboBox2.Items.Add("=");//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//comboBox2.Items.Add(">");//comboBox2.Items.Add(">=");//comboBox2.Items.Add("<");//comboBox2.Items.Add("<=");//}//}//privatevoidbutton1_Click(objectsender,EventArgse)//{//if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text==""))//{//MessageBox.Show("查询条件不能为空");//return;//}//stringsql="select*fromSoccerClubwhere";//stringstr="";//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//str=comboBox1.Text+comboBox2.Text+textBox1.Text;//}//else//{//str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";//}//sql+=str;//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse)//{//System.Diagnostics.Process.Start(linkLabel1.Text);//}//privatevoidlabel1_Click(objectsender,EventArgse)//{//}//}//}全部帮你注释了。
,这个邪恶!哈哈哈
解决方案:
引用5楼shencb的回复:
//namespaceSoccerVIP//{//publicpartialclassForm2:Form//{//DataSetmyDataSet;//存放从数据库取来的数据的。//OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接//OleDbDataAdaptermyDataAdapter;//用来执行SQL命令//publicForm2()//{//InitializeComponent();//}//publicvoidRefreshDG()//{//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//stringsql="select*fromSoccerClub";//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidForm2_Load(objectsender,EventArgse)//{//comboBox1.Items.Clear();//comboBox1.Items.Add("tID");//comboBox1.Items.Add("firstname");//comboBox1.Items.Add("lastname");//comboBox1.Items.Add("tel");//comboBox1.Items.Add("address");//comboBox1.Items.Add("favoriteTeam");//comboBox1.Items.Add("rentTime");//comboBox1.Items.Add("coach");//try//{//stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="//+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";//myOleConn=newOleDbConnection(ConStr);//myOleConn.Open();//myDataSet=newDataSet();//RefreshDG();//}//catch//{//MessageBox.Show("连接数据库有问题,未连接成功。");//}//}//privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)//{//comboBox2.Items.Clear();//comboBox2.Items.Add("=");//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//comboBox2.Items.Add(">");//comboBox2.Items.Add(">=");//comboBox2.Items.Add("<");//comboBox2.Items.Add("<=");//}//}//privatevoidbutton1_Click(objectsender,EventArgse)//{//if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text==""))//{//MessageBox.Show("查询条件不能为空");//return;//}//stringsql="select*fromSoccerClubwhere";//stringstr="";//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//str=comboBox1.Text+comboBox2.Text+textBox1.Text;//}//else//{//str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";//}//sql+=str;//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse)//{//System.Diagnostics.Process.Start(linkLabel1.Text);//}//privatevoidlabel1_Click(objectsender,EventArgse)//{//}//}//}全部帮你注释了。
好样滴
解决方案:
解决方案:
引用5楼shencb的回复:
//namespaceSoccerVIP//{//publicpartialclassForm2:Form//{//DataSetmyDataSet;//存放从数据库取来的数据的。//OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接//OleDbDataAdaptermyDataAdapter;//用来执行SQL命令//publicForm2()//{//InitializeComponent();//}//publicvoidRefreshDG()//{//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//stringsql="select*fromSoccerClub";//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidForm2_Load(objectsender,EventArgse)//{//comboBox1.Items.Clear();//comboBox1.Items.Add("tID");//comboBox1.Items.Add("firstname");//comboBox1.Items.Add("lastname");//comboBox1.Items.Add("tel");//comboBox1.Items.Add("address");//comboBox1.Items.Add("favoriteTeam");//comboBox1.Items.Add("rentTime");//comboBox1.Items.Add("coach");//try//{//stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="//+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";//myOleConn=newOleDbConnection(ConStr);//myOleConn.Open();//myDataSet=newDataSet();//RefreshDG();//}//catch//{//MessageBox.Show("连接数据库有问题,未连接成功。");//}//}//privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)//{//comboBox2.Items.Clear();//comboBox2.Items.Add("=");//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//comboBox2.Items.Add(">");//comboBox2.Items.Add(">=");//comboBox2.Items.Add("<");//comboBox2.Items.Add("<=");//}//}//privatevoidbutton1_Click(objectsender,EventArgse)//{//if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text==""))//{//MessageBox.Show("查询条件不能为空");//return;//}//stringsql="select*fromSoccerClubwhere";//stringstr="";//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//str=comboBox1.Text+comboBox2.Text+textBox1.Text;//}//else//{//str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";//}//sql+=str;//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse)//{//System.Diagnostics.Process.Start(linkLabel1.Text);//}//privatevoidlabel1_Click(objectsender,EventArgse)//{//}//}//}全部帮你注释了。
你太逗了如果楼主这些代码都不会,那你得好好看看书了
解决方案:
我来帮帮楼主吧,随手打的,借用前面的了namespaceSoccerVIP{publicpartialclassForm2:Form{DataSetmyDataSet;//存放从数据库取来的数据的。OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接OleDbDataAdaptermyDataAdapter;//用来执行SQL命令publicForm2(){InitializeComponent();}publicvoidRefreshDG(){//移除旧的数据if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}//读取所有的SocerClub数据,并绑定到dataGridView1上stringsql="select*fromSoccerClub";myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//执行sqlmyDataAdapter.Fill(myDataSet,"SoccerClub");//填充datasetdataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//绑定数据源}privatevoidForm2_Load(objectsender,EventArgse){//设置下拉框选项comboBox1.Items.Clear();comboBox1.Items.Add("tID");comboBox1.Items.Add("firstname");comboBox1.Items.Add("lastname");comboBox1.Items.Add("tel");comboBox1.Items.Add("address");comboBox1.Items.Add("favoriteTeam");comboBox1.Items.Add("rentTime");comboBox1.Items.Add("coach");try//异常处理{//链接数据库stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";myOleConn=newOleDbConnection(ConStr);myOleConn.Open();//读取数据myDataSet=newDataSet();RefreshDG();}catch{MessageBox.Show("连接数据库有问题,未连接成功。");}}privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){//根据comboBox1选择内容,设置comboBox2的选项comboBox2.Items.Clear();comboBox2.Items.Add("=");if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){comboBox2.Items.Add(">");comboBox2.Items.Add(">=");comboBox2.Items.Add("<");comboBox2.Items.Add("<=");}}privatevoidbutton1_Click(objectsender,EventArgse){if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text=="")){MessageBox.Show("查询条件不能为空");return;}stringsql="select*fromSoccerClubwhere";stringstr="";if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){str=comboBox1.Text+comboBox2.Text+textBox1.Text;}else{str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";}sql+=str;//拼sqlif(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}//根据条件查询myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){//打开某个链接System.Diagnostics.Process.Start(linkLabel1.Text);}privatevoidlabel1_Click(objectsender,EventArgse){}}}
解决方案:
namespaceSoccerVIP{publicpartialclassForm2:Form{DataSetmyDataSet;//存放从数据库取来的数据的。OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接OleDbDataAdaptermyDataAdapter;//用来执行SQL命令publicForm2(){InitializeComponent();}publicvoidRefreshDG(){if(myDataSet.Tables.Contains("SoccerClub"))//如果取来的数据是SoccerClub,那么就移除SoccerClub{myDataSet.Tables.Remove("SoccerClub");}stringsql="select*fromSoccerClub";//查出所有SoccerClub的数据myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//dataGridView1绑定数据源}privatevoidForm2_Load(objectsender,EventArgse){comboBox1.Items.Clear();//清空comboBox1的值comboBox1.Items.Add("tID");//comboBox1的集合中添加下面的属性comboBox1.Items.Add("firstname");comboBox1.Items.Add("lastname");comboBox1.Items.Add("tel");comboBox1.Items.Add("address");comboBox1.Items.Add("favoriteTeam");comboBox1.Items.Add("rentTime");comboBox1.Items.Add("coach");try//判断异常处理{stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";myOleConn=newOleDbConnection(ConStr);myOleConn.Open();myDataSet=newDataSet();RefreshDG();}catch{MessageBox.Show("连接数据库有问题,未连接成功。");}}privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){comboBox2.Items.Clear();//清空comboBox2集合内容comboBox2.Items.Add("=");//comboBox2集合增加等号if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach"))//如果comboBox1的text内容等于tID,并且等于tel,并且等于coach,那么comboBox2的集合增加下面内容{comboBox2.Items.Add(">");comboBox2.Items.Add(">=");comboBox2.Items.Add("<");comboBox2.Items.Add("<=");}}privatevoidbutton1_Click(objectsender,EventArgse){if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text==""))//如果textBox1,comboBox1,comboBox2为空,那么输出查询条件不能为空。{MessageBox.Show("查询条件不能为空");return;}stringsql="select*fromSoccerClubwhere";//stringstr="";if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach"))//如果上述条件成立,那么下面三个控件的内容相加,elsecomboBox1.Text内容加两个引号{str=comboBox1.Text+comboBox2.Text+textBox1.Text;}else{str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";}sql+=str;if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){System.Diagnostics.Process.Start(linkLabel1.Text);}privatevoidlabel1_Click(objectsender,EventArgse){}}}
解决方案:
//名称空间为SoccerVIPnamespaceSoccerVIP{//类名为Form2publicpartialclassForm2:Form{DataSetmyDataSet;//存放从数据库取来的数据的。OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接OleDbDataAdaptermyDataAdapter;//用来执行SQL命令publicForm2(){//初始化界面InitializeComponent();}publicvoidRefreshDG(){//如果myData数据库的数据表中含有SoccerClub表if(myDataSet.Tables.Contains("SoccerClub")){//移除SoccerClub表myDataSet.Tables.Remove("SoccerClub");}//sql读取表SoccerClub所有结果集stringsql="select*fromSoccerClub";//实例化一个myDataAdapter对象myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//填充myDataSet里面的数据myDataAdapter.Fill(myDataSet,"SoccerClub");//将dataGridView1的数据源设置为表SoccerClub,这样可以显示dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidForm2_Load(objectsender,EventArgse){//combox1控件先清除所有项comboBox1.Items.Clear();//combox1控件添加ID行comboBox1.Items.Add("tID");//combox1控件添加firstname行comboBox1.Items.Add("firstname");//combox1控件添加lastname行comboBox1.Items.Add("lastname");//combox1控件添加tel行comboBox1.Items.Add("tel");//combox1控件添加address行comboBox1.Items.Add("address");//combox1控件添加favoriteTeam行comboBox1.Items.Add("favoriteTeam");//combox1控件添加rentTime行comboBox1.Items.Add("rentTime");//combox1控件添加coach行comboBox1.Items.Add("coach");try{//声明连接字符串,可以在数据源管理器里面获取该字符串stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";//连接类实例化myOleConn=newOleDbConnection(ConStr);//打开连接myOleConn.Open();//实例化一个数据集用来存储数据myDataSet=newDataSet();//调用RefreshDG函数RefreshDG();}catch{//当上面操作异常时弹出连接数据库有问题,未连接成功的提示MessageBox.Show("连接数据库有问题,未连接成功。");}}privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){//comboBox2控件先清除所有项comboBox2.Items.Clear();//combox1控件添加"="行comboBox2.Items.Add("=");//加入combox1的选项包含tID或tel或coachif((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){//combox2就添加">"行comboBox2.Items.Add(">");//combox2就添加">="行comboBox2.Items.Add(">=");//combox2就添加"<"行comboBox2.Items.Add("<");//combox2就添加"<="行comboBox2.Items.Add("<=");}}privatevoidbutton1_Click(objectsender,EventArgse){//假如数据为空if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text=="")){//弹出查询条件不能为空提示MessageBox.Show("查询条件不能为空");return;}stringsql="select*fromSoccerClubwhere";stringstr="";if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){str=comboBox1.Text+comboBox2.Text+textBox1.Text;}else{str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";}sql+=str;//如果myData数据库的数据表中含有SoccerClub表if(myDataSet.Tables.Contains("SoccerClub")){//移除SoccerClub表myDataSet.Tables.Remove("SoccerClub");}//实例化一个myDataAdapter对象myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//填充myDataSet里面的数据myDataAdapter.Fill(myDataSet,"SoccerClub");//将dataGridView1的数据源设置为表SoccerClub,这样可以显示dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){//启动一个进程名为linkLabel1.Text的连接System.Diagnostics.Process.Start(linkLabel1.Text);}privatevoidlabel1_Click(objectsender,EventArgse){}}}
解决方案:
namespaceSoccerVIP{///<summary>///我看不懂,但他确实实现了XXXX功能///</summary>publicpartialclassForm2:Form{DataSetmyDataSet;OleDbConnectionmyOleConn;OleDbDataAdaptermyDataAdapter;publicForm2(){InitializeComponent();}publicvoidRefreshDG(){if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}stringsql="select*fromSoccerClub";myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidForm2_Load(objectsender,EventArgse){comboBox1.Items.Clear();comboBox1.Items.Add("tID");comboBox1.Items.Add("firstname");comboBox1.Items.Add("lastname");comboBox1.Items.Add("tel");comboBox1.Items.Add("address");comboBox1.Items.Add("favoriteTeam");comboBox1.Items.Add("rentTime");comboBox1.Items.Add("coach");try{stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";myOleConn=newOleDbConnection(ConStr);myOleConn.Open();myDataSet=newDataSet();RefreshDG();}catch{MessageBox.Show("连接数据库有问题,未连接成功。");}}privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){comboBox2.Items.Clear();comboBox2.Items.Add("=");if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){comboBox2.Items.Add(">");comboBox2.Items.Add(">=");comboBox2.Items.Add("<");comboBox2.Items.Add("<=");}}privatevoidbutton1_Click(objectsender,EventArgse){if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text=="")){MessageBox.Show("查询条件不能为空");return;}stringsql="select*fromSoccerClubwhere";stringstr="";if((comboBox1.Text=="tID")||(comboBox1.Text=="tel")||(comboBox1.Text=="coach")){str=comboBox1.Text+comboBox2.Text+textBox1.Text;}else{str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";}sql+=str;if(myDataSet.Tables.Contains("SoccerClub")){myDataSet.Tables.Remove("SoccerClub");}myDataAdapter=newOleDbDataAdapter(sql,myOleConn);myDataAdapter.Fill(myDataSet,"SoccerClub");dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];}privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){System.Diagnostics.Process.Start(linkLabel1.Text);}privatevoidlabel1_Click(objectsender,EventArgse){}}}
我觉得你这样就够了
解决方案:
引用9楼hwenycocodq520的回复:
来这里叫别人帮做作业,你家人知道吗
+10086
解决方案:
引用5楼shencb的回复:
//namespaceSoccerVIP//{//publicpartialclassForm2:Form//{//DataSetmyDataSet;//存放从数据库取来的数据的。//OleDbConnectionmyOleConn;//连接对象,建立本程序和数据库的连接//OleDbDataAdaptermyDataAdapter;//用来执行SQL命令//publicForm2()//{//InitializeComponent();//}//publicvoidRefreshDG()//{//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//stringsql="select*fromSoccerClub";//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidForm2_Load(objectsender,EventArgse)//{//comboBox1.Items.Clear();//comboBox1.Items.Add("tID");//comboBox1.Items.Add("firstname");//comboBox1.Items.Add("lastname");//comboBox1.Items.Add("tel");//comboBox1.Items.Add("address");//comboBox1.Items.Add("favoriteTeam");//comboBox1.Items.Add("rentTime");//comboBox1.Items.Add("coach");//try//{//stringConStr=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="//+System.Environment.CurrentDirectory+@"/dbSoccer.mdb";//myOleConn=newOleDbConnection(ConStr);//myOleConn.Open();//myDataSet=newDataSet();//RefreshDG();//}//catch//{//MessageBox.Show("连接数据库有问题,未连接成功。");//}//}//privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)//{//comboBox2.Items.Clear();//comboBox2.Items.Add("=");//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//comboBox2.Items.Add(">");//comboBox2.Items.Add(">=");//comboBox2.Items.Add("<");//comboBox2.Items.Add("<=");//}//}//privatevoidbutton1_Click(objectsender,EventArgse)//{//if((textBox1.Text=="")||(comboBox1.Text=="")||(comboBox2.Text==""))//{//MessageBox.Show("查询条件不能为空");//return;//}//stringsql="select*fromSoccerClubwhere";//stringstr="";//if((comboBox1.Text=="tID")||//(comboBox1.Text=="tel")||//(comboBox1.Text=="coach"))//{//str=comboBox1.Text+comboBox2.Text+textBox1.Text;//}//else//{//str=comboBox1.Text+comboBox2.Text+"'"+textBox1.Text+"'";//}//sql+=str;//if(myDataSet.Tables.Contains("SoccerClub"))//{//myDataSet.Tables.Remove("SoccerClub");//}//myDataAdapter=newOleDbDataAdapter(sql,myOleConn);//myDataAdapter.Fill(myDataSet,"SoccerClub");//dataGridView1.DataSource=myDataSet.Tables["SoccerClub"];//}//privatevoidlinkLabel1_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse)//{//System.Diagnostics.Process.Start(linkLabel1.Text);//}//privatevoidlabel1_Click(objectsender,EventArgse)//{//}//}//}全部帮你注释了。
这个吊
解决方案:
我靠。好人真多啊。。。
解决方案:
懒汉:namespaceSoccerVIP{publicpartialclassForm2:Form{......}}
老实的懒汉:namespaceSoccerVIP{///<summary>///创建者:u013342695///我看不懂,但他确实实现了XXXX功能///</summary>publicpartialclassForm2:Form{......}}
装X的懒汉:namespaceSoccerVIP{///<summary>///创建者:u013342695///实现XXXX功能///</summary>publicpartialclassForm2:Form{......}}
解决方案:
在这里让别人帮你写作业你父母知道吗