Results 1 to 2 of 2

Thread: Displaying Data from Database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Posts
    104

    Displaying Data from Database

    I created some code to bind data to a datagrid control however when the user clicks on the button no data is displayed. I am using MySQL as my database system and have Imports System.Data.Odbc added in the beginning of my code. I have also added a control to the webform. I tried the code both without and with the grid on the form. Any help is appreciated. I apologize for being so full of questions but im new to ASP.NET and im trying to get these few issues straight so I can start full out using the features instead of VB 6.0.

    Code:

    VB Code:
    1. Private Sub cmdView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdView.Click
    2.         Dim myConn As String
    3.         myConn = "Driver={MySQL ODBC 3.51 Driver};SERVER=appserver.domain.net;PORT=3306;DATABASE=database;UID=Username;PASSWORD=Password;OPTION=147458;"
    4.         Dim mySQL As New OdbcConnection(myConn)
    5.         mySQL.Open()
    6.         Dim dg1 As New DataGrid()
    7.         Dim selectQuery As String
    8.         selectQuery = "SELECT type, make, serial, custID, sysID FROM stamissys WHERE type = '" & txtType.Text & "'"
    9.         Dim datacommand As New OdbcCommand(selectQuery, mySQL)
    10.         dg1.DataSource = datacommand.ExecuteReader
    11.         dg1.DataBind()
    12.         mySQL.Close()
    13.     End Sub
    Last edited by Polariss; Jul 7th, 2005 at 06:41 AM. Reason: Change Title

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: Displaying Data from Database

    ok you need to add dg1 to somethings controls.. Page.Controls.Add(dg1) will append it to the bottom of the page....

    VB Code:
    1. Private Sub cmdView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdView.Click
    2.         Dim myConn As String
    3.         myConn = "Driver={MySQL ODBC 3.51 Driver};SERVER=appserver.domain.net;PORT=3306;DATABASE=database;UID=Username;PASSWORD=Password;OPTIO  N=147458;"
    4.         Dim mySQL As New OdbcConnection(myConn)
    5.         mySQL.Open()
    6.         Dim dg1 As New DataGrid()
    7.         Dim selectQuery As String
    8.         selectQuery = "SELECT type, make, serial, custID, sysID FROM stamissys WHERE type = '" & txtType.Text & "'"
    9.         Dim datacommand As New OdbcCommand(selectQuery, mySQL)
    10.         dg1.DataSource = datacommand.ExecuteReader
    11.         dg1.DataBind()
    12.         Controls.Add(dg1);
    13.         mySQL.Close()
    14.     End Sub
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width