Results 1 to 5 of 5
  1. #1

    Default Need help for vb.net with adodb connection


    Hi! im currently studying about the adodb connection and somehow i cant display the db on datagridview using adodb connection. I have a sample code of my recent project. Please help and reply asap thanks!

    Private Sub GetDatatoGrid()
    Try
    Dim adconn As New ADODB.Connection()


    adconn.ConnectionString = "DRIVER=MySQL ODBC 5.1 Driver;Server=10.237.250.252;uid=root;pwd=c0k3floa t;database=test;port=3306""Server=10.237.250.252;u id=root;pwd=c0k3float;database=test;port=3306"
    adconn.Open()
    Dim rs As New ADODB.Recordset()
    rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
    rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
    rs.Open("select * from earvin", adconn.ConnectionString)
    rs.ActiveConnection = Nothing
    adconn.Close()
    Dim da As New System.Data.OleDb.OleDbDataAdapter()
    Dim ds As New DataSet()
    da.Fill(ds, rs, "Table")
    3: For x As Integer = 0 To ds.Tables(0).Rows.Count - 1
    dataGV.Rows.Insert(0) 'this will add a new record on top, always
    dataGV.Rows(0).Cells(0).Value = ds.Tables(0).Rows(x)("id")
    dataGV.Rows(0).Cells(1).Value = ds.Tables(0).Rows(x)("name")
    dataGV.Rows(0).Cells(2).Value = ds.Tables(0).Rows(x)("age")
    dataGV.Rows(0).Cells(3).Value = ds.Tables(0).Rows(x)("position")

    Next
    Catch ex As Exception
    MsgBox(ex.Message)


    End Try



    p.s. may i know the meaning of da.fill and its parameter esp the string parameter on it

  2. #2
    Solution 1
    dataGV.DataSource = ds.Tables(0)
    (ds.Tables(0) is a datatable and can be directly bind to the datagridview)

    you can do this one bro it will automatically bind the columns from your datatable, given that ds.Tables(0) has data.

    Solution 2, you can replace your loop with this one
    Dim lintDVRow as integer = 0

    For Each DocRow As DataRow In ds.Tables(0).Rows
    dataGV.Rows(lintDVRow).Cells(0).Value = DocRow("id")
    dataGV.Rows(lintDVRow).Cells(1).Value = DocRow("name")
    dataGV.Rows(lintDVRow).Cells(2).Value = DocRow("age")
    dataGV.Rows(lintDVRow).Cells(3).Value = DocRow("position")
    lintDVRow = lintDVRow + 1
    Next

  3. #3
    Quote Originally Posted by earvinnill View Post
    Hi! im currently studying about the adodb connection and somehow i cant display the db on datagridview using adodb connection. I have a sample code of my recent project. Please help and reply asap thanks!

    p.s. may i know the meaning of da.fill and its parameter esp the string parameter on it
    da.fill - means your data adapter(da) will fill the dataset(ds) with values according to your query(""select * from earvin"") and will have a table name table "Table" (This is the string you inputted).

  4. #4
    Quote Originally Posted by RainRiku View Post
    da.fill - means your data adapter(da) will fill the dataset(ds) with values according to your query(""select * from earvin"") and will have a table name table "Table" (This is the string you inputted).
    so what do you i need to do for the table name table? i currently have existing db on my sql browser

  5. #5
    it depends on how you use it, da.Fill(ds, rs, "Table") this statement will name the table "Table" so instead calling the table by this ds.Tables(0), you can call it using the table name ds.Tables("Table")

    ds.Tables(0) and ds.Tables("Table") is basically just referring to a one table

  6.    Advertisement

Similar Threads

 
  1. I need help for Windows XP Pro with SP3 OEM Product Key
    By Trunkz "The Pitbull" A. in forum Windows Software
    Replies: 4
    Last Post: 03-03-2012, 09:16 AM
  2. Replies: 8
    Last Post: 06-05-2011, 01:50 AM
  3. need help for network connection --
    By tishop1234 in forum Networking & Internet
    Replies: 15
    Last Post: 04-19-2011, 09:18 PM
  4. Need help in VB 6.0 and VB.Net?
    By rhex_tendo in forum Programming
    Replies: 10
    Last Post: 08-31-2010, 01:01 PM
  5. help for vb.net users?
    By krmz69 in forum Programming
    Replies: 2
    Last Post: 06-29-2010, 09:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top