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 課程號(hào) from 課程列表 where [課程號(hào)]='" + 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 成績表(成績單號(hào),學(xué)生號(hào),課程號(hào)) value('"+ cjh + "','" + id+"',''" + dt.Rows[0][0].ToString()+"')";17 SqlCommand sqlcom2 = new SqlCommand(sqlstr2, sqlcon);18 sqlcon.Close();19 }20 }
這是確定選課按鈕的代碼,?我是想將課程號(hào)和學(xué)生號(hào)合并為成績單號(hào),做為主鍵。運(yùn)行沒有錯(cuò)誤提示,就是插入不了,粉嫩新人求指導(dǎo),請(qǐng)寫詳細(xì)點(diǎn)。第一次發(fā)帖,分少莫怪。
請(qǐng)教,這段代碼怎么不能成功?
富國滬深
2018-12-06 18:19:27