private static int jszcj( string sid)
{//课程基本分计算方法
string str = "select sum(cid) from stu_c where sid="+sid;//获取总课程数
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand(str,con);
string zkcs=com.ExecuteScalar().ToString();
int zkc = int.Parse(kcs);
string str1 = "select sum(xueshi) from course where cid=(select cid from stu_c where sid='"+sid+"')";//获得总学时
com.CommandText = str1;
string zxues = com.ExecuteScalar().ToString();
int zxs = int.Parse(sues);
string str2 = "select stu_c.cid,stu_c.chengji,course.xueshi from (course,stu_c) where stu_c.sid='"+sid+"'";//获得每门课对应的成绩和课时
DataSet ds=new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(str2, con);
sda.Fill(ds);
double sum=0;
ds.Tables[0].Rows//在这就不知到怎么写了,用什么方法来接收这些成绩和课时;
}
我是想实现一个计算公式
for(int i;i<zkc;i++){ sum=sum+chengji[i]*xueshi[i]/zxs}
{//课程基本分计算方法
string str = "select sum(cid) from stu_c where sid="+sid;//获取总课程数
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand(str,con);
string zkcs=com.ExecuteScalar().ToString();
int zkc = int.Parse(kcs);
string str1 = "select sum(xueshi) from course where cid=(select cid from stu_c where sid='"+sid+"')";//获得总学时
com.CommandText = str1;
string zxues = com.ExecuteScalar().ToString();
int zxs = int.Parse(sues);
string str2 = "select stu_c.cid,stu_c.chengji,course.xueshi from (course,stu_c) where stu_c.sid='"+sid+"'";//获得每门课对应的成绩和课时
DataSet ds=new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(str2, con);
sda.Fill(ds);
double sum=0;
ds.Tables[0].Rows//在这就不知到怎么写了,用什么方法来接收这些成绩和课时;
}
我是想实现一个计算公式
for(int i;i<zkc;i++){ sum=sum+chengji[i]*xueshi[i]/zxs}
{
ds.Tables[0].Rows[i]["chengji"].tostring()
ds.Tables[0].Rows[i]["xueshi"].tostring()}
可以dgv.DataSource=ds.Tables[0];