?
Solved

Visual Basic

Posted on 2011-04-20
19
Medium Priority
?
214 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
0
Comment
Question by:snhandle
  • 8
  • 6
  • 5
19 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35438440
Have you defined strPath somewhere?

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

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35438452
Also I just realized that it has nothing to do with Excel :)

Sid
0
 

Author Comment

by:snhandle
ID: 35438462
Where I will define this path? what should be the full script for it?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35438577
Ok, Let me create an example for you.

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35438592
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
 

Author Comment

by:snhandle
ID: 35451905
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
 
LVL 14

Accepted Solution

by:
dejaanbu earned 2000 total points
ID: 35453486
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
 
LVL 14

Expert Comment

by:dejaanbu
ID: 35453492
pls remove the text Student(I) from line 25.. it was a mistake while typing
0
 

Author Comment

by:snhandle
ID: 35453734
so I should replace my script with the above script, right?
0
 
LVL 14

Expert Comment

by:dejaanbu
ID: 35453741
yes, please try and let me know
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35453751
Also did you try the script that I gave? You will have to amend it a little bit.

Sid
0
 

Author Comment

by:snhandle
ID: 35462303
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
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35462321
>>>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
 

Author Comment

by:snhandle
ID: 35462396
Actually, I am using dejaanbu: script.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35462433
ok :)

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35462434
Unsubscribing from this thread :)

Sid
0
 
LVL 14

Expert Comment

by:dejaanbu
ID: 35464493
are you getting number of rows in TotalRec when tracing?
0
 
LVL 14

Expert Comment

by:dejaanbu
ID: 35464509
otherwise, please try this link :  http://support.microsoft.com/kb/164922
0
 

Author Closing Comment

by:snhandle
ID: 35808511
Good
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question