我设计的数据表testdetail为:
GridView中有数据,形式为
我现在想把GridView中的内容(已绑定了数值)存到testdetai中,
我使用的方法是
DataBase db = new DataBase();
foreach (GridViewRow dr in GridView2.Rows)//保存试卷单选题信息
{
string single = "insert into testdetail(examinationid,typekind,typeid,score) values(" + afterID + ",'单选题'," + int.Parse(((Label)dr.FindControl("Label3")).Text) + "," + int.Parse(txtSingleFen.Text) + ")";
db.Insert(single);
}
Insert是我已经在Database.cs中定义了的:
public int Insert(string XSqlString)
{
int Count = -1;
Open();
SqlCommand cmd = new SqlCommand(XSqlString, Connection);
Count = cmd.ExecuteNonQuery();
Close();
return Count;
}
运行之后发现testdetail中这些数据并没有被存储进去,不知道是为什么...
由于初学也不知道自己写的是不是对的,请大家帮忙指导一下,非常感谢!