1 sqlcon = new SqlConnection(strCon); 2 string id = HttpContext.Current.Session["Id"].ToString(); 3 4 for (int i = 0; i <= GridView1.Rows.Count - 1; i++) 5 { 6 CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); 7 if (cbox.Checked == true) 8 { 9 sqlcon.Open();10 string sqlstr1="Select 課程號 from 課程列表 where [課程號]='" + GridView1.DataKeys[i].Value + "'"; 11 SqlCommand sqlcom = new SqlCommand(sqlstr1, sqlcon);12 SqlDataAdapter sqladapt = new SqlDataAdapter(sqlcom);13 DataTable dt = new DataTable();14 sqladapt.Fill(dt);15 string cjh = dt.Rows[0][0].ToString() + id;16 string sqlstr2 = "insert into 成績表(成績單號,學生號,課程號) value('"+ cjh + "','" + id+"',''" + dt.Rows[0][0].ToString()+"')";17 SqlCommand sqlcom2 = new SqlCommand(sqlstr2, sqlcon);18 sqlcon.Close();19 }20 }
這是確定選課按鈕的代碼,?我是想將課程號和學生號合并為成績單號,做為主鍵。運行沒有錯誤提示,就是插入不了,粉嫩新人求指導,請寫詳細點。第一次發帖,分少莫怪。
請教,這段代碼怎么不能成功?
富國滬深
2018-12-06 18:19:27