PublicClass显示学生信息DimrsAsNewADODB.RecordsetDimconnAsNewADODB.ConnectionPublicFunctionconnect_db()AsADODB.Connection'Dim conn As New ADODB.ConnectionDimconstrAsStringconstr=("Driver={SQL Server};server=PC-201105311336\SQLEXPRESS;Uid=sa;Pwd=123456;Database=jiaxiaoai")
conn.Open(constr)
connect_db=conn'sql = "select * from student"End FunctionPrivateSubfirstbtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesfirstbtn.Click
rs.MoveFirst()
xuehaotext.Text=rs(0).Value
nametext.Text=rs(1).ValueIf(rs(2).Value=0)Thensextext.Text=""Elsesextext.Text=Str(rs(2).Value)EndIfIf(rs(3).Value=0)Thenscoretext.Text=""Elsescoretext.Text=Str(rs(3).Value)EndIfEnd SubPrivateSubupbtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesupbtn.Click
rs.MovePrevious()Ifrs.BOF=TrueThenrs.MoveFirst()EndIfxuehaotext.Text=rs(0).Value
nametext.Text=rs(1).ValueIf(rs(2).Value=0)Thensextext.Text=""Elsesextext.Text=Str(rs(2).Value)EndIfIf(rs(3).Value=0)Thenscoretext.Text=""Elsescoretext.Text=Str(rs(3).Value)EndIfEnd SubPrivateSubdownbtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesdownbtn.Click
rs.MoveNext()Ifrs.EOF=TrueThenrs.MoveLast()EndIfxuehaotext.Text=rs(0).Value
nametext.Text=rs(1).ValueIf(rs(2).Value=0)Thensextext.Text=""Elsesextext.Text=Str(rs(2).Value)EndIfIf(rs(3).Value=0)Thenscoretext.Text=""Elsescoretext.Text=Str(rs(3).Value)EndIfEnd SubPrivateSubendbtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesendbtn.Click
rs.MoveLast()
xuehaotext.Text=rs(0).Value
nametext.Text=rs(1).ValueIf(rs(2).Value=0)Thensextext.Text=""Elsesextext.Text=Str(rs(2).Value)EndIfIf(rs(3).Value=0)Thenscoretext.Text=""Elsescoretext.Text=Str(rs(3).Value)EndIfEnd SubPrivateSub显示学生信息_Load(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMyBase.Load'窗口初始化函数DimsqlAsStringsql="select * from student"conn=connect_db()
rs.Open(sql, conn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)'connect(sql)rs.MoveFirst()
xuehaotext.Text=rs(0).Value
nametext.Text=rs(1).ValueIf(rs(2).Value=0)Thensextext.Text=""Elsesextext.Text=Str(rs(2).Value)EndIfIf(rs(3).Value=0)Thenscoretext.Text=""Elsescoretext.Text=Str(rs(3).Value)EndIfEnd SubPrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesinsertbtn.ClickDimsexDimscore
sex=Val(sextext.Text)
score=Val(scoretext.Text)'sql = "insert into student ('" & xuehaotext.Text & "','" & nametext.Text & "','" & sex & "','" & score & "')"'rs.Open(sql, conn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)rs.AddNew()
rs(0).Value=xuehaotext.Text
rs(1).Value=nametext.Text
rs(2).Value=sex
rs(3).Value=score
rs.Update()End SubPrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesupdatebtn.ClickDimsexDimscore
sex=Val(sextext.Text)
score=Val(scoretext.Text)
rs(0).Value=xuehaotext.Text
rs(1).Value=nametext.Text
rs(2).Value=sex
rs(3).Value=score
rs.Update()End SubPrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesdeletebtn.Click
rs.Delete()End SubPrivateSuballbtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesallbtn.ClickEnd SubEnd Class