通过动态创建表来实现成绩存放
2007-05-14 19:49
411 查看
经过一番思量,感觉成绩存放采用动态创建表更合理。本来想着通过查询DB中现有表名来确定某专业成绩是否存在,后来决定重新建一个只有一个字段(专业名)的表来记录已经有哪些专业的成绩表存在。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data.OleDb;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// Summary description for DbOperation
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public class DbOperation
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string Department;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
double StuID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string Course;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
double Score;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public static string connString = ConfigurationManager.AppSettings["provider"].ToString()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["dbPath"])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ ";";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public DbOperation()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public DbOperation(string department,double stuID,string course,double score)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Department = department;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
StuID = stuID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Course = course;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Score = score;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void InsertGradeOfDepartment()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection Conn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string sql = "select * from GradeAmount where Department='"+Department+"'";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand Cmd = new OleDbCommand(sql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbDataReader dr = Cmd.ExecuteReader();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (dr.Read())
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsertGrade();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreatGradeTable();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsertStu2GradeTable();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SignDepartment();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsertGrade();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void CreatGradeTable()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string CreatSql = "Create table " + Department
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ " (StuID Number, StuName Text)";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string GetCourseSql = "select CourseName from Course where Department='"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ Department + "'";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection CreatConn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreatConn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand CreatCmd = new OleDbCommand(CreatSql, CreatConn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreatCmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbDataAdapter da = new OleDbDataAdapter(GetCourseSql, CreatConn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataSet ds = new DataSet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
da.Fill(ds, "Course");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string temp = ds.Tables[0].Rows[i][0].ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
temp = temp.Replace('.', '_');
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string AlterSql = "alter table " + Department + " add [" + temp + "] Number;";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand AlterCmd = new OleDbCommand(AlterSql, CreatConn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AlterCmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
catch
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
finally
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreatConn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void InsertStu2GradeTable()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection Conn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string GetStuSql = "select StuID,StuName from StuInfo where Department='"+Department+"'";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbDataAdapter da = new OleDbDataAdapter(GetStuSql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataSet ds = new DataSet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
da.Fill(ds, "Stu");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i=0; i < ds.Tables[0].Rows.Count; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
double stuId =(double) ds.Tables[0].Rows[i][0];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string stuName = ds.Tables[0].Rows[i][1].ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string InsertSql = "Insert Into " + Department + " (StuID,StuName) Values("+stuId+",'"+stuName+"')";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand InsCmd = new OleDbCommand(InsertSql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsCmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void SignDepartment()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection Conn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string sql = "Insert into GradeAmount (Department) Values('"+Department+"')";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand Cmd = new OleDbCommand(sql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void InsertGrade()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string InsertSql = "update "+Department+" set "+Course+"="+Score+" where StuID="+StuID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection Conn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand InsertCmd = new OleDbCommand(InsertSql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsertCmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
catch
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
finally
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//虽然这将导致很多代码重写,但是感觉无论是为了学习还是仅仅为了毕业设计都是值得的。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data.OleDb;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// Summary description for DbOperation
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public class DbOperation
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string Department;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
double StuID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string Course;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
double Score;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public static string connString = ConfigurationManager.AppSettings["provider"].ToString()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["dbPath"])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ ";";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public DbOperation()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public DbOperation(string department,double stuID,string course,double score)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Department = department;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
StuID = stuID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Course = course;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Score = score;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void InsertGradeOfDepartment()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection Conn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string sql = "select * from GradeAmount where Department='"+Department+"'";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand Cmd = new OleDbCommand(sql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbDataReader dr = Cmd.ExecuteReader();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (dr.Read())
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsertGrade();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreatGradeTable();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsertStu2GradeTable();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SignDepartment();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsertGrade();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void CreatGradeTable()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string CreatSql = "Create table " + Department
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ " (StuID Number, StuName Text)";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string GetCourseSql = "select CourseName from Course where Department='"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
+ Department + "'";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection CreatConn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreatConn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand CreatCmd = new OleDbCommand(CreatSql, CreatConn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreatCmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbDataAdapter da = new OleDbDataAdapter(GetCourseSql, CreatConn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataSet ds = new DataSet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
da.Fill(ds, "Course");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string temp = ds.Tables[0].Rows[i][0].ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
temp = temp.Replace('.', '_');
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string AlterSql = "alter table " + Department + " add [" + temp + "] Number;";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand AlterCmd = new OleDbCommand(AlterSql, CreatConn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AlterCmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
catch
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
finally
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreatConn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void InsertStu2GradeTable()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection Conn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string GetStuSql = "select StuID,StuName from StuInfo where Department='"+Department+"'";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbDataAdapter da = new OleDbDataAdapter(GetStuSql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataSet ds = new DataSet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
da.Fill(ds, "Stu");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i=0; i < ds.Tables[0].Rows.Count; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
double stuId =(double) ds.Tables[0].Rows[i][0];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string stuName = ds.Tables[0].Rows[i][1].ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string InsertSql = "Insert Into " + Department + " (StuID,StuName) Values("+stuId+",'"+stuName+"')";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand InsCmd = new OleDbCommand(InsertSql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsCmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void SignDepartment()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection Conn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string sql = "Insert into GradeAmount (Department) Values('"+Department+"')";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand Cmd = new OleDbCommand(sql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Cmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void InsertGrade()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string InsertSql = "update "+Department+" set "+Course+"="+Score+" where StuID="+StuID;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbConnection Conn = new OleDbConnection(connString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
OleDbCommand InsertCmd = new OleDbCommand(InsertSql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
InsertCmd.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
catch
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
finally
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//虽然这将导致很多代码重写,但是感觉无论是为了学习还是仅仅为了毕业设计都是值得的。
相关文章推荐
- JAVA动态模块的设计实现以及如何通过newInstance()来创建带参的构造类实例
- 通过动态代理(Proxy)实现的数据库连接池的创建连接与归还链接的操作的简单的实现流程
- JBPM流程通过Aciton动态创建TaskInstance来实现“会签”
- JBPM流程通过Aciton动态创建TaskInstance来实现“会签”
- js动态创建上传表单通过iframe模拟Ajax实现无刷新
- php 通过__callStatic魔术方法实现方法的动态创建和延迟绑定
- 《JBPM流程通过Aciton动态创建TaskInstance来实现“会签”》2
- JBPM流程通过Aciton动态创建TaskInstance来实现“会签”
- js动态创建上传表单通过iframe模拟Ajax实现无刷新
- Swift微博项目--Swift中通过类名字符串创建类以及动态加载控制器的实现
- 通过动态代理(Proxy)实现的数据库连接池的创建连接与归还链接的操作的简单的实现流程
- CCRenderTexture(动态创建纹理类 ---通过OpenGL方法 可以实现截屏功能)
- (设计模式)简单工厂模式之通过配置文件动态创建实现类
- java 通过代码实现动态选择数据源
- 动态创建并且实现Fragment
- jQuery+json实现动态创建复杂表格table的方法
- JQuery动态创建DOM、表单元素的实现代码
- C语言创建链表错误之通过指针参数申请动态内存实例分析
- 关于jquery实现动态创建表格和动态显示数据的问题?
- vc下动态创建access数据库的实现