Visual Basic

I am trying to figure out why the table is not getting filled up. Attach is the  code. thanks
code.doc
snhandleAsked:
Who is Participating?
 
dejaanbuCommented:
you r creating a variable like this in button click         Dim Student() As Object
 and re-defined the size of the object array. but no values are assigned to array.

check whether this works.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strsql As String = "Select * From stable"
        Dim strpath As String = "provider=microsoft.jet.oledb.4.0 ; " & "Data Source = C:\students.mdb"
        Dim StudentData As New OleDb.OleDbDataAdapter(strsql, strpath)
        Dim DatStudent As New DataTable
        Dim TotalRec As Integer
       ' Dim Student() As Object
      '  ReDim Student(TotalRec - 1)
        StudentData.Fill(DatStudent)

        Dim I As Integer

        For I = 0 To TotalRec - 1 Step 1
            flexgrid.Row = I + 1
            flexgrid.Col = 0
            flexgrid.Text = DatStudent.Rows(I).Item("STNO")
            flexgrid.Col = 1
            flexgrid.Text = DatStudent.Rows(I).Item("name")
            flexgrid.Col = 2
            flexgrid.Text =DatStudent.Rows(I).Item("credits")
            flexgrid.Col = 3
            flexgrid.Text = DatStudent.Rows(I).Item("objtype")
            flexgrid.Col = 4
            flexgrid.Text = DatStudent.Rows(I).Item("tuition")Student(I)

        Next I
    End Sub

Open in new window

0
 
SiddharthRoutCommented:
Have you defined strPath somewhere?

        Dim StudentData As New OleDb.OleDbDataAdapter(strsql, strpath)

Sid
0
 
SiddharthRoutCommented:
Also I just realized that it has nothing to do with Excel :)

Sid
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
snhandleAuthor Commented:
Where I will define this path? what should be the full script for it?
0
 
SiddharthRoutCommented:
Ok, Let me create an example for you.

Sid
0
 
SiddharthRoutCommented:
UNTESTED

See this example. I am sending the data in the data table to console rather than flex. I am sure you can take care of that?

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Windows.Forms
Imports System.Resources

Public Class StudentFile
    Shared OleDbConnection As System.Data.OleDb.OleDbConnection

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        ConnectToDB()
        Dim OleDBCmd As System.Data.OleDb.OleDbCommand
        OleDBCmd = New System.Data.OleDb.OleDbCommand()

        OleDBCmd.CommandText = "Select * From stable"
        OleDBCmd.Connection = OleDbConnection

        Dim OleDBAdptr As System.Data.OleDb.OleDbDataAdapter
        OleDBAdptr = New System.Data.OleDb.OleDbDataAdapter()

        OleDBAdptr.SelectCommand = OleDBCmd

        Dim dtSet As System.Data.DataSet
        dtSet = New System.Data.DataSet()
        CType(dtSet, System.ComponentModel.ISupportInitialize).EndInit()

        OleDBAdptr.Fill(dtSet)

        Dim dataTable As DataTable = dtSet.Tables(0)

        '~~> Check if dataTable is not empty
        If dataTable.Rows.Count <> 0 Then
            Dim recordNumber As Integer = Convert.ToInt32(dataTable.Rows(0)(0))

            Console.WriteLine(recordNumber.ToString)
            Console.WriteLine(Convert.ToString(dataTable.Rows(0)(1)))
            Console.WriteLine(Convert.ToString(dataTable.Rows(0)(2)))
            Console.WriteLine(Convert.ToString(dataTable.Rows(0)(3)))
        Else
            Console.WriteLine("No record found")
        End If
        DisconnectFrmDB()
    End Sub

    Shared Sub ConnectToDB()
        OleDbConnection = New System.Data.OleDb.OleDbConnection()

        OleDbConnection.ConnectionString = _
           "provider=microsoft.jet.oledb.4.0 ; " & "Data Source = C:\students.mdb"
        Try
            OleDbConnection.Open()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub

    Shared Sub DisconnectFrmDB()
        Try
            OleDbConnection.Close()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Class

Open in new window


Sid
0
 
snhandleAuthor Commented:
Yes I did defin the strt path as you can see in my script but it is still not working. You can look at my script if I wrote it wrong. thanks
0
 
dejaanbuCommented:
pls remove the text Student(I) from line 25.. it was a mistake while typing
0
 
snhandleAuthor Commented:
so I should replace my script with the above script, right?
0
 
dejaanbuCommented:
yes, please try and let me know
0
 
SiddharthRoutCommented:
Also did you try the script that I gave? You will have to amend it a little bit.

Sid
0
 
snhandleAuthor Commented:
When I click the button (button1_Click) to fill the grid nothing happens. Do you know why? It would be very helpful if you can give me the code to fill the flexgrid.
 
0
 
SiddharthRoutCommented:
>>>When I click the button (button1_Click) to fill the grid nothing happens.

If that is for me then that is because the output is redirected to the console. See Line 37 onwards.

I will amend that for grid. First could you please confirm if you are getting the right results in the console?

Sid
0
 
snhandleAuthor Commented:
Actually, I am using dejaanbu: script.
0
 
SiddharthRoutCommented:
ok :)

Sid
0
 
SiddharthRoutCommented:
Unsubscribing from this thread :)

Sid
0
 
dejaanbuCommented:
are you getting number of rows in TotalRec when tracing?
0
 
dejaanbuCommented:
otherwise, please try this link :  http://support.microsoft.com/kb/164922
0
 
snhandleAuthor Commented:
Good
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.