public partial class ScoreForm : Form
{
public ScoreForm()
{
InitializeComponent();
}
private void 学生成绩BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.学生成绩BindingSource.EndEdit();
this.学生成绩TableAdapter.Update(this.dBSchoolDataSet.学生成绩);
}
private void 查询ToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.学生成绩TableAdapter.Fill(this.dBSchoolDataSet.学生成绩, 班级名称ToolStripComboBox.Text, 学期名称ToolStripComboBox.Text);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void ScoreForm_Load(object sender, EventArgs e)
{
String MySQLConnectionString = global::MySchool.Properties.Settings.Default.DBSchoolConnectionString;
string MySQL = "SELECT DISTINCT * FROM [班级设置] ";
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
System.Data.DataTable MyTable = new System.Data.DataTable();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
MyAdapter.Fill(MyTable);
foreach (DataRow MyRow in MyTable.Rows)
{
this.班级名称ToolStripComboBox.Items.Add(MyRow["班级名称"].ToString());
this.班级名称ComboBox.Items.Add(MyRow["班级名称"].ToString());
}
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
}
private void 学生姓名ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.学生姓名ComboBox.SelectedValue.ToString() != "System.Data.DataRowView")
{
this.学籍编号TextBox.Text = this.学生姓名ComboBox.SelectedValue.ToString();
}
}
private void 学期名称ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
this.课程设置TableAdapter.FillBySortCurse(this.dBSchoolDataSet.课程设置, this.班级名称ComboBox.Text, this.学期名称ComboBox.Text);
}
这个是一个别人的例子,我想知道这个例子里面,那个BindingNavigator是如何实现功能的,我看了代码,都没有发现有新增,删除得功能的代码实现,但是,这个例子里面却可以实现这些功能。那么BindingNavigator的这些功能是要怎么才能使用的?
还有一个查询功能,在代码中,我看不出来,它按了查询之后,是怎么样的操作,它是怎么把数据显示到datagridview里面去的!?
有人能帮我解析一下吗,由于新手,所以,只能把这么多代码一次过放上来,分不多,希望有人可以帮下我这个菜鸟吧!
今晚,平安夜,祝大家平安快乐!谢谢!
private void 班级名称ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
this.学期名称ComboBox.Items.Clear();
String MySQLConnectionString = global::MySchool.Properties.Settings.Default.DBSchoolConnectionString;
string MySQL = "SELECT DISTINCT [学期名称] FROM [课程设置] WHERE ([班级名称] ='" + this.班级名称ComboBox.Text + "')";
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
System.Data.DataTable MyTable = new System.Data.DataTable();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
MyAdapter.Fill(MyTable);
foreach (DataRow MyRow in MyTable.Rows)
{
this.学期名称ComboBox.Items.Add(MyRow["学期名称"].ToString());
}
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
|