|
-
Jul 6th, 2005, 08:12 PM
#1
Thread Starter
Lively Member
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:
Private Sub cmdView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdView.Click
Dim myConn As String
myConn = "Driver={MySQL ODBC 3.51 Driver};SERVER=appserver.domain.net;PORT=3306;DATABASE=database;UID=Username;PASSWORD=Password;OPTION=147458;"
Dim mySQL As New OdbcConnection(myConn)
mySQL.Open()
Dim dg1 As New DataGrid()
Dim selectQuery As String
selectQuery = "SELECT type, make, serial, custID, sysID FROM stamissys WHERE type = '" & txtType.Text & "'"
Dim datacommand As New OdbcCommand(selectQuery, mySQL)
dg1.DataSource = datacommand.ExecuteReader
dg1.DataBind()
mySQL.Close()
End Sub
Last edited by Polariss; Jul 7th, 2005 at 06:41 AM.
Reason: Change Title
-
Jul 7th, 2005, 01:09 PM
#2
Frenzied Member
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:
Private Sub cmdView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdView.Click
Dim myConn As String
myConn = "Driver={MySQL ODBC 3.51 Driver};SERVER=appserver.domain.net;PORT=3306;DATABASE=database;UID=Username;PASSWORD=Password;OPTIO N=147458;"
Dim mySQL As New OdbcConnection(myConn)
mySQL.Open()
Dim dg1 As New DataGrid()
Dim selectQuery As String
selectQuery = "SELECT type, make, serial, custID, sysID FROM stamissys WHERE type = '" & txtType.Text & "'"
Dim datacommand As New OdbcCommand(selectQuery, mySQL)
dg1.DataSource = datacommand.ExecuteReader
dg1.DataBind()
Controls.Add(dg1);
mySQL.Close()
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|