using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _201412104043_韩瑞.ScoreFolder
{
public partial class frmCourseInfo : Form
{
public frmCourseInfo()
{
InitializeComponent();
}
SqlConnection con = DBhelper.Getcon();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter dap = new SqlDataAdapter();
DataTable dtCourse = new DataTable();
private void frmScoreInfo_Load(object sender, EventArgs e)
{
cmd.Connection = con;
cmd.CommandText = "select * from Course;";
dap.SelectCommand = cmd;
dap.Fill(dtCourse);
DGVcourse.DataSource = dtCourse;
DGVcourse.Columns[0].HeaderText = "课号";
DGVcourse.Columns[1].HeaderText = "课程名";
DGVcourse.Columns[2].HeaderText = "学分";
DGVcourse.Columns[3].HeaderText = "学时";
DGVcourse.Columns[4].HeaderText = "课程类型";
}
private void btnSava_Click(object sender, EventArgs e)
{
SqlCommandBuilder cbr = new SqlCommandBuilder();
cbr.DataAdapter = dap;
dap.InsertCommand = cbr.GetInsertCommand();
dap.UpdateCommand = cbr.GetUpdateCommand();
dap.DeleteCommand = cbr.GetDeleteCommand();
dap.Update(dtCourse);
}
string curNo;
string curName;
int curCredit;
int Hour;
string Typ;
private void btnAddCourse_Click(object sender, EventArgs e)
{
curNo=txtCourseNum.Text;
curName=txtCourseName.Text;
curCredit=Convert.ToInt32( NudCredit.Value);
Hour=Convert.ToInt32(NudHour.Value);
Typ=cobCourseType.SelectedText;
string str = "INSERT INTO Course " +
"([curNo] " +
",[curName]" +
",[curCredit]" +
",[curPeriod]" +
",[curType]) " +
" VALUES " +
"('"+ curNo +"'" +
" ,'" + curName + "'" +
" ,'" + curCredit + "'" +
" ,'" + Hour + "'" +
" ,'" + Typ + "')";
cmd.CommandText = str;
dap.InsertCommand = cmd;
cmd.CommandText = "select * from Course;";
dap.SelectCommand = cmd;
dap.Fill(dtCourse);
DGVcourse.DataSource = dtCourse;
}
}
}