The statement looks correct. I copied and pasted directly into TOAD, connecting to the same database as the connection string in VB is pointing to, and I got 4 rows of data in TOAD.
Also as far as the GridView goes, I don't need to set anything special on it, do i? Anything other than adding it to the web form via the Toolbox and setting the "(ID)" value in the properties?
Hmm, with all of the correspondence back and forth, I think I might have answered the question; you're setting the DataSource and DataMember properties after the Page_Load event. You need to set these properties (when done programmatically as you do) in
the Page_Load event handler or earlier. Just add the Page_Load event handler from the dropdown lists at the top of the Text Editor.
The DataMember property is fairly simple, because it is a fixed string. I'm uncertain about the code you use to construct the SELECT statement, can it be created at page load time?
Thanks
Carsten
Please click Mark as Answer if this post is of help to you. :-)
So, the code for Page_Load event handler and Button Click event handler would look like this?
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cn.ConnectionString = ConfigurationManager.ConnectionStrings("ptchomfg").ConnectionString
Dim sdaShipData As New OleDbDataAdapter("SELECT rcta.interface_header_attribute1 order_number, rcta.trx_number invoice_number, " & _
"trunc(rcta.creation_date) invoice_date " & _
"FROM ar.ra_customer_trx_all rcta " & _
"WHERE rcta.interface_header_attribute1 = '" & txtOrderNumber.Text & "'", cn)
Dim dsShipData As New DataSet()
Me.dgShipData.Visible = True
dgShipData.DataSource = dsShipData
dgShipData.DataMember = "Table1"
dgShipData.DataBind()
End Sub
Protected Sub btnRetrieveData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRetrieveData.Click
cn.Open()
sdaShipData.Fill(dsShipData, "Table1")
cn.Close()
End Sub
If that is right, it doesnt recognize "sdaShipData" and "dsShipData"... how do I get that to work being in a different Sub ?
Yes, that is a good question and certainly one that relates to your class design. I would move all variables that are used in more than one method to just below the class declaration and make them private, as you have with the connection object. This makes
the variables member variables, that are inaccessible to users of your class. I realize that it is a web form and thus unlikely to be accessed, but this is a general design consideration.
It could look like this:
Public Class ShipDataUpdate
Inherits System.Web.UI.Page
Private cn As New OleDbConnection
Dim sdaShipData As New OleDbDataAdapter
Dim dsShipData As New DataSet()
Now, you need to adjust the remaining code, because you're binding in the Page_Load event handler, which is fine, but you're updating or filling the DataSet in the btnRetrieveData_Click event handler, which is executed after the Page_Load event handler. I suggest to try to make it a little simpler first, to get it working, and this code should do it (not complete as far as the class goes and not tested).
Public Class ShipDataUpdate
Inherits System.Web.UI.Page
Private cn As New OleDbConnection
Dim sdaShipData As New OleDbDataAdapter
Dim dsShipData As New DataSet()Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cn.ConnectionString = ConfigurationManager.ConnectionStrings("ptchomfg").ConnectionString
sdaShipData = New OleDbDataAdapter("SELECT rcta.interface_header_attribute1 order_number, rcta.trx_number invoice_number, " & _
06. "trunc(rcta.creation_date) invoice_date " & _
07. "FROM ar.ra_customer_trx_all rcta " & _
08. "WHERE rcta.interface_header_attribute1 = '" & txtOrderNumber.Text & "'", cn)
sdaShipData.Fill(dsShipData, "Table1")
Me.dgShipData.Visible = True
Me.dgShipData.DataSource = dsShipData
Me.dgShipData.DataMember = "Table1"
dgShipData.DataBind()
End Sub
Protected Sub btnRetrieveData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRetrieveData.Click
'sdaShipData.Fill(dsShipData, "Table1")
End Sub
Thanks
Carsten
Please click Mark as Answer if this post is of help to you. :-)
Drrwho
Member
2 Points
39 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 06:34 PM|LINK
The statement looks correct. I copied and pasted directly into TOAD, connecting to the same database as the connection string in VB is pointing to, and I got 4 rows of data in TOAD.
Drrwho
Member
2 Points
39 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 06:36 PM|LINK
I dont have a Page_Load event hander in my code... should I? Right now I just have the button click event handler.
Drrwho
Member
2 Points
39 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 06:38 PM|LINK
Also as far as the GridView goes, I don't need to set anything special on it, do i? Anything other than adding it to the web form via the Toolbox and setting the "(ID)" value in the properties?
integrasol
Star
12155 Points
2355 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 06:41 PM|LINK
Hmm, with all of the correspondence back and forth, I think I might have answered the question; you're setting the DataSource and DataMember properties after the Page_Load event. You need to set these properties (when done programmatically as you do) in the Page_Load event handler or earlier. Just add the Page_Load event handler from the dropdown lists at the top of the Text Editor.
The DataMember property is fairly simple, because it is a fixed string. I'm uncertain about the code you use to construct the SELECT statement, can it be created at page load time?
Carsten
Please click Mark as Answer if this post is of help to you. :-)
My Blog
integrasol
Star
12155 Points
2355 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 06:43 PM|LINK
No, that ought to do it, but you can post the HTML markup for the GridView control, and I'll check for you.
Carsten
Please click Mark as Answer if this post is of help to you. :-)
My Blog
Drrwho
Member
2 Points
39 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 06:54 PM|LINK
So, the code for Page_Load event handler and Button Click event handler would look like this?
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load cn.ConnectionString = ConfigurationManager.ConnectionStrings("ptchomfg").ConnectionString Dim sdaShipData As New OleDbDataAdapter("SELECT rcta.interface_header_attribute1 order_number, rcta.trx_number invoice_number, " & _ "trunc(rcta.creation_date) invoice_date " & _ "FROM ar.ra_customer_trx_all rcta " & _ "WHERE rcta.interface_header_attribute1 = '" & txtOrderNumber.Text & "'", cn) Dim dsShipData As New DataSet() Me.dgShipData.Visible = True dgShipData.DataSource = dsShipData dgShipData.DataMember = "Table1" dgShipData.DataBind() End Sub Protected Sub btnRetrieveData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRetrieveData.Click cn.Open() sdaShipData.Fill(dsShipData, "Table1") cn.Close() End SubIf that is right, it doesnt recognize "sdaShipData" and "dsShipData"... how do I get that to work being in a different Sub ?
Drrwho
Member
2 Points
39 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 06:57 PM|LINK
There isn't much there...
<asp:GridView ID="dgShipData" runat="server"> </asp:GridView>That's all I found. Also, in the properties, AutoGenerateColumns is set to True... is that right?
Drrwho
Member
2 Points
39 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 07:04 PM|LINK
Nevermind, I put the DIM statements for sdaShipData and dsShipData above the two event handlers. Not getting any issues from VS now on that piece.
Drrwho
Member
2 Points
39 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 07:08 PM|LINK
Guess I spoke too soon... by having the sdaShipData defined above the Page_Load event handler, it gave me an error...
"Object reference not set to an instance of an object"
and it highlighted sdaShipData in yellow.
Is that saying I can't define the new data adapter outside an event handler?
integrasol
Star
12155 Points
2355 Posts
Re: New to VB... working with dataset and gridview to display data on web form
Jul 26, 2010 07:08 PM|LINK
Yes, that is a good question and certainly one that relates to your class design. I would move all variables that are used in more than one method to just below the class declaration and make them private, as you have with the connection object. This makes the variables member variables, that are inaccessible to users of your class. I realize that it is a web form and thus unlikely to be accessed, but this is a general design consideration.
It could look like this:
Public Class ShipDataUpdate Inherits System.Web.UI.Page Private cn As New OleDbConnection Dim sdaShipData As New OleDbDataAdapter Dim dsShipData As New DataSet()Now, you need to adjust the remaining code, because you're binding in the Page_Load event handler, which is fine, but you're updating or filling the DataSet in the btnRetrieveData_Click event handler, which is executed after the Page_Load event handler. I suggest to try to make it a little simpler first, to get it working, and this code should do it (not complete as far as the class goes and not tested).
Public Class ShipDataUpdate Inherits System.Web.UI.Page Private cn As New OleDbConnection Dim sdaShipData As New OleDbDataAdapter Dim dsShipData As New DataSet()Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load cn.ConnectionString = ConfigurationManager.ConnectionStrings("ptchomfg").ConnectionString sdaShipData = New OleDbDataAdapter("SELECT rcta.interface_header_attribute1 order_number, rcta.trx_number invoice_number, " & _ 06. "trunc(rcta.creation_date) invoice_date " & _ 07. "FROM ar.ra_customer_trx_all rcta " & _ 08. "WHERE rcta.interface_header_attribute1 = '" & txtOrderNumber.Text & "'", cn) sdaShipData.Fill(dsShipData, "Table1") Me.dgShipData.Visible = True Me.dgShipData.DataSource = dsShipData Me.dgShipData.DataMember = "Table1" dgShipData.DataBind() End Sub Protected Sub btnRetrieveData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRetrieveData.Click 'sdaShipData.Fill(dsShipData, "Table1") End SubCarsten
Please click Mark as Answer if this post is of help to you. :-)
My Blog