We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Visual Basic

Medium Priority
230 Views
Last Modified: 2012-05-11
I am trying to figure out why the table is not getting filled up. Attach is the  code. thanks
code.doc
Comment
Watch Question

Have you defined strPath somewhere?

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

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

Sid

Author

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

Sid
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

Author

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
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
pls remove the text Student(I) from line 25.. it was a mistake while typing

Author

Commented:
so I should replace my script with the above script, right?

Commented:
yes, please try and let me know
Also did you try the script that I gave? You will have to amend it a little bit.

Sid

Author

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.
 
>>>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

Author

Commented:
Actually, I am using dejaanbu: script.
ok :)

Sid
Unsubscribing from this thread :)

Sid

Commented:
are you getting number of rows in TotalRec when tracing?

Commented:
otherwise, please try this link :  http://support.microsoft.com/kb/164922

Author

Commented:
Good
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.