没有错误但是就是不能向数据库中填加数据!????
DropDownList MyDDL=new DropDownList ();
foreach ( Control MyControl in pnlQuestions.Controls )//pnlQuestions是Panel控件。
{
if (MyControl.GetType ().FullName == "System.Web.UI .WebControls .DropDownList ")
{ MyDDL=(DropDownList)MyControl;
DBInsert.CommandText ="Insert Into SurveyResponses (SurveyQuestionID,SurveyResponse) values ("+MyDDL.ID .ToString ().Substring (2,2)+",'"+MyDDL.SelectedItem .Text .ToString ().Replace ("'","''")+"')";
DBInsert.Connection =DBConn;
DBInsert.Connection .Open ();
DBInsert.ExecuteNonQuery ();}
}
表SurveyResponses中用SurveyQuestionID和SurveyResponseID(int 长度为4)SurveyResponse(varchar 长度为50)