回 帖 发 新 帖 刷新版面

主题:宝宝帮我看一下呀!!

Dim tablename As String = "couset"
        Dim strsql As String = "selec 课程名 from couset where 专业='" & ComboBox1.Text & "'"
        ExecuteSQL(searchSQL, tablename)
        Dim newrow As DataRow
        Dim i As Int16
        For i = 1 To [color=FF0000]newrow.count-1[/color]

        Next
        End Sub
中间的代码怎么写呀??中间的意思是i的值从1到记录的总条数-1,这里我不会。
然后就是for.....next之间的代码了。怎么把记录从数据库写到listbox2中。能给我具体点的代码吗??谢谢大虾了1

回复列表 (共6个回复)

沙发

中间的意思是i的值从1到记录的总条数-1?


什么意思看不懂.
在解释一下。

板凳

怎么把记录从数据库写到listbox2中,就是说把这个for ..next语句写完整。

这句可以不用理他了。“中间的意思是i的值从1到记录的总条数-1“

3 楼


        ListBox2.Items.Clear()
        Dim stkinfo As New stuInfo
        stkinfo = GetInfo(0)
        Dim j As Integer
        Dim Item(6) As String
        For j = 0 To stkinfo.count - 1
            stkinfo = GetInfo(j)
            Item(0) = stkinfo.xuehao
            Item(1) = stkinfo.xingming
            Item(2) = stkinfo.yingyu
            Item(3) = stkinfo.dianzhi
            Item(4) = stkinfo.vc
            Item(5) = stkinfo.shuju
            ListBox2.Items.Insert(j, New ListViewItem(Item))
        Next j

4 楼

dim reader as sqldatareader
dim cmd as new sqlcommand(strsql,conn)
............

reader=cmd.executeReader
     Do While reader.Read
            For i = 0 To reader.FieldCount - 1
                ListBox1.Items.Add(reader.Item(i) & vbNewLine)
            Next
        Loop

试下看看

5 楼

Public Function GetInfo(ByVal index As Integer)
        Dim ds As New DataSet
        ds.Clear()
        sqlstr = "SELECT * FROM  student"
        ds = GetDataFromDB(sqlstr)
        Dim stkinfo As New stuInfo
        Try

            If Not ds Is Nothing Then '''''用这句话就可以了 ?????为什么????
                'If ds.Tables(0).Rows.Count > 0 Then'''''用这句话当帐号不存在时就会有异常?????为什么????
                stkinfo.xuehao = ds.Tables(0).Rows(index)("xuehao")
                stkinfo.xingming = ds.Tables(0).Rows(index)("xingming")
                stkinfo.yingyu = ds.Tables(0).Rows(index)("yingyu")
                stkinfo.dianzhi = ds.Tables(0).Rows(index)("dianzhi")
                stkinfo.vc = ds.Tables(0).Rows(index)("vc")
                stkinfo.shuju = ds.Tables(0).Rows(index)("shuju")
                stkinfo.pass = ds.Tables(0).Rows(index)("pass")
                stkinfo.ess = True
                stkinfo.count = ds.Tables(0).Rows.Count
                'Return stkinfo
                ' ElseIf ds Is Nothing Then
            Else
                stkinfo.ess = False ''''当帐号不存在就显示为false
            End If
        Catch ex As Exception
            MessageBox.Show("有异常!!", "提示消息")
        End Try
        Return stkinfo
    End Function

6 楼

谢谢宝哥,我太爱你了。。

我来回复

您尚未登录,请登录后再回复。点此登录或注册