问题描述
目的:用DropDownList中选择一个学生,再用DataGrid中显示他的分数小弟开了2个Access:A)StudentInfo的资料表:StudentIdName1Sam2MayB)StudentScore的资料表:StudentIdExamQuiz1777729990在webform1.asp.vb編寫了:ImportsSystem.Data.OleDbPublicClassUsingDataReaderInheritsSystem.Web.UI.PagePrivateSubPage_Load_(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_HandlesMyBase.LoadIfNotPage.IsPostBackThenRead_DataBase()DimdrAsDataRowEndIfEndSubPrivateSubRead_DataBase()DimcnnAsNewOleDbConnection_("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:studentkk.mdb")DimstrSQLAsString="SELECTStudentId,NameFROMStudentInfo"&"SELECTQuiz,ExamFROMStudentScoreWHEREStudentId=2"DimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrycnn.Open()dr=cmd.ExecuteReader()DoWhiledr.ReadDimtoDisplayAsString=_dr("StudentId").ToString()+":"+dr("Name")DropDownList1.Items.Add(toDisplay)DataGrid1.DataSource=drDataGrid1.DataBind()LoopCatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndSubEndClass他说语法错,但可以怎样做呢?请帮忙
解决方案
解决方案二:
天〜没人懂吗?
解决方案三:
能说说,具体是哪里语法有错么?没时间全看一遍。。。
解决方案四:
你这个代码,很不规范,没人愿意看,最起码的大括号都没有,先把代码规范了,再放上来,应该会有人帮你解决,态度,态度,态度啊。
解决方案五:
能说说,具体是哪里语法有错么?没时间全看一遍。。。
解决方案六:
用VB寫,说是Form语法错误看得明白吗?
解决方案七:
该回复于2011-12-05 10:14:25被版主删除
解决方案八:
PrivateSubRead_DataBase()DimcnnAsNewOleDbConnection_("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:studentkk.mdb")DimcmdAsNewOleDbCommand("SELECTStudentId,NameFROMStudentInfo",cnn)DimdrAsOleDbDataReaderTrycnn.Open()dr=cmd.ExecuteReader()DoWhiledr.ReadDropDownList1.Items.Add(NewListItemWith{.Text=dr("StudentId").ToString()+":"+dr("Name"),.Value=dr("StudentId").ToString()})Loopcnn.Close()CatchexAsExceptionResponse.Write(ex.Message)FinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndSubProtectedSubDropDownList1_SelectedIndexChanged(senderAsObject,eAsEventArgs)HandlesDropDownList1.SelectedIndexChangedTryDimcnnAsNewOleDbConnection_("Provider=Microsoft.ACE.OLEDB.12.0;DataSource="&Server.MapPath("kk.accdb"))DimcmdAsNewOleDbDataAdapter("SELECTb.name,a.Quiz,a.ExamFROMStudentScorealeftjoinStudentInfobona.StudentId=b.StudentIdWHEREa.StudentId="&DropDownList1.SelectedValue,cnn)DimdatatableAsNewDataTablecmd.Fill(datatable)cnn.Close()DataGrid1.DataSource=datatableDataGrid1.DataBind()CatchexAsExceptionResponse.Write(ex.ToString()+"<br/>")EndTryEndSub<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="true"></asp:DropDownList><asp:GridViewID="DataGrid1"runat="server"></asp:GridView>
解决方案九:
PrivateSubRead_DataBase()DimcnnAsNewOleDbConnection_("Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Server.MapPath("kk.mdb"))DimcmdAsNewOleDbCommand("SELECTStudentId,NameFROMStudentInfo",cnn)DimdrAsOleDbDataReaderTrycnn.Open()dr=cmd.ExecuteReader()DoWhiledr.ReadDropDownList1.Items.Add(NewListItemWith{.Text=dr("StudentId").ToString()+":"+dr("Name"),.Value=dr("StudentId").ToString()})Loopcnn.Close()CatchexAsExceptionResponse.Write(ex.Message)FinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndSubProtectedSubDropDownList1_SelectedIndexChanged(senderAsObject,eAsEventArgs)HandlesDropDownList1.SelectedIndexChangedTryDimcnnAsNewOleDbConnection_("Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Server.MapPath("kk.mdb"))DimcmdAsNewOleDbDataAdapter("SELECTb.name,a.Quiz,a.ExamFROMStudentScorealeftjoinStudentInfobona.StudentId=b.StudentIdWHEREa.StudentId="&DropDownList1.SelectedValue,cnn)DimdatatableAsNewDataTablecmd.Fill(datatable)cnn.Close()DataGrid1.DataSource=datatableDataGrid1.DataBind()CatchexAsExceptionResponse.Write(ex.ToString()+"<br/>")EndTryEndSub<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="true"></asp:DropDownList><asp:GridViewID="DataGrid1"runat="server"></asp:GridView>
解决方案十:
引用3楼dhy8084的回复:
你这个代码,很不规范,没人愿意看,最起码的大括号都没有,先把代码规范了,再放上来,应该会有人帮你解决,态度,态度,态度啊。
VB...花括号....end....
解决方案十一:
如果这样写但是DataGird没有反应谁懂?ImportsSystem.Data.OleDbPublicClassUsingDataReaderInheritsSystem.Web.UI.PageDimcnnAsNewOleDbConnection_("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:studentkk.mdb")PrivateSubPage_Load_(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_HandlesMyBase.LoadIfcnn.State=ConnectionState.ClosedThencnn.Open()EndIfIfNotPage.IsPostBackThenDimstrSQLAsString="SELECTStudentId,NameFROMStudentInfo"DimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrydr=cmd.ExecuteReader()DropDownList1.DataTextField="Name"DropDownList1.DataValueField="StudentId"DropDownList1.DataSource=drDropDownList1.DataBind()CatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndIfEndSubPrivateSubRead_DataBase()DimstrSQLAsString=_"SELECTQuiz,ExamFROMStudentScoreWHEREStudentId="&_DropDownList1.SelectedValueDimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrydr=cmd.ExecuteReader()DataGrid1.DataSource=drDataGrid1.DataBind()CatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndSubSubDropDownList1_SelectedIndexChanged_(ByValsenderAsObject,ByValeAsEventArgs)Read_DataBase()EndSubEndClassImportsSystem.Data.OleDbPublicClassUsingDataReaderInheritsSystem.Web.UI.PageDimcnnAsNewOleDbConnection_("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:tempdb1.mdb")PrivateSubPage_Load_(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_HandlesMyBase.LoadIfcnn.State=ConnectionState.ClosedThencnn.Open()EndIfIfNotPage.IsPostBackThenDimstrSQLAsString="SELECTStudentId,NameFROMStudentInfo"DimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrydr=cmd.ExecuteReader()DropDownList1.DataTextField="Name"DropDownList1.DataValueField="StudentId"DropDownList1.DataSource=drDropDownList1.DataBind()CatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndIfEndSubPrivateSubRead_DataBase()DimstrSQLAsString=_"SELECTQuiz,ExamFROMStudentScoreWHEREStudentId="&_DropDownList1.SelectedValueDimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrydr=cmd.ExecuteReader()DataGrid1.DataSource=drDataGrid1.DataBind()CatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndSubSubDropDownList1_SelectedIndexChanged_(ByValsenderAsObject,ByValeAsEventArgs)Read_DataBase()EndSubEndClassImportsSystem.Data.OleDbPublicClassUsingDataReaderInheritsSystem.Web.UI.PageDimcnnAsNewOleDbConnection_("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:tempdb1.mdb")PrivateSubPage_Load_(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_HandlesMyBase.LoadIfcnn.State=ConnectionState.ClosedThencnn.Open()EndIfIfNotPage.IsPostBackThenDimstrSQLAsString="SELECTStudentId,NameFROMStudentInfo"DimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrydr=cmd.ExecuteReader()DropDownList1.DataTextField="Name"DropDownList1.DataValueField="StudentId"DropDownList1.DataSource=drDropDownList1.DataBind()CatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndIfEndSubPrivateSubRead_DataBase()DimstrSQLAsString=_"SELECTQuiz,ExamFROMStudentScoreWHEREStudentId="&_DropDownList1.SelectedValueDimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrydr=cmd.ExecuteReader()DataGrid1.DataSource=drDataGrid1.DataBind()CatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndSubSubDropDownList1_SelectedIndexChanged_(ByValsenderAsObject,ByValeAsEventArgs)Read_DataBase()EndSubEndClass
解决方案十二:
如果这样写但是DataGird没有反应谁懂?ImportsSystem.Data.OleDbPublicClassUsingDataReaderInheritsSystem.Web.UI.PageDimcnnAsNewOleDbConnection_("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:studentkk.mdb")PrivateSubPage_Load_(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)_HandlesMyBase.LoadIfcnn.State=ConnectionState.ClosedThencnn.Open()EndIfIfNotPage.IsPostBackThenDimstrSQLAsString="SELECTStudentId,NameFROMStudentInfo"DimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrydr=cmd.ExecuteReader()DropDownList1.DataTextField="Name"DropDownList1.DataValueField="StudentId"DropDownList1.DataSource=drDropDownList1.DataBind()CatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndIfEndSubPrivateSubRead_DataBase()DimstrSQLAsString=_"SELECTQuiz,ExamFROMStudentScoreWHEREStudentId="&_DropDownList1.SelectedValueDimcmdAsNewOleDbCommand(strSQL,cnn)DimdrAsOleDbDataReaderTrydr=cmd.ExecuteReader()DataGrid1.DataSource=drDataGrid1.DataBind()CatchexAsExceptionLabel1.Text=ex.MessageFinallyIfNotcmdIsNothingThencmd.Dispose()EndIfIfNotdrIsNothingThendr.Close()EndIfIfNotcnnIsNothingThencnn.Close()cnn.Dispose()EndIfEndTryEndSubSubDropDownList1_SelectedIndexChanged_(ByValsenderAsObject,ByValeAsEventArgs)Read_DataBase()EndSubEndClass