473,902 Members | 5,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data in dataset but not displaying in gridview

49 New Member
Hello, I'm new to this asp.net 2.0 I need help??
My database is coming from AS400 which uses odbc Commands. i have data in the dataset but nothing showing in my gridview. However the data does show on the page. Could you please see what I'm doing wrong.

My code is down below
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  2.  
  3.  
  4.         Dim myconnection As OdbcConnection
  5.         Dim myCommand As OdbcDataAdapter
  6.         Dim mydataset As New DataSet
  7.         Dim gvResults As DataTable
  8.         Dim loop1 As Integer
  9.         Dim numrows As Integer
  10.         Dim mysql As String
  11.         Dim Order As Integer
  12.         Order = CInt(txtOrderNumber.Text)
  13.  
  14.  
  15.         mysql = "select  line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp  from rmsfiles2.obcop200 where ordno = " & Order
  16.         myconnection = New OdbcConnection("DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=XXXXX;System=xxx.xxx.xxx.xxx")
  17.  
  18.         myCommand = New OdbcDataAdapter(mysql, myconnection)
  19.  
  20.         myCommand.Fill(mydataset, "OBCOP200")
  21.  
  22.         gvResults = New DataTable
  23.         gvResults = mydataset.Tables(0)
  24.  
  25.         numrows = gvResults.Rows.Count
  26.  
  27.         If numrows = 0 Then
  28.             txtOrderNumber.Text = "Order#" & txtOrderNumber.Text & " invalid order number"
  29.  
  30.         Else
  31.             txtOrderNumber.Text = ""
  32.  
  33.             For loop1 = 0 To numrows - 1
  34.  
  35.                 Response.Write(Server.HtmlEncode(gvResults.Rows(loop1).Item("ordno")) & " " & Server.HtmlEncode(gvResults.Rows(loop1).Item("quano")) & " " & Server.HtmlEncode(gvResults.Rows(loop1).Item("quana")) & " " & Server.HtmlEncode(gvResults.Rows(loop1).Item("quans")) & " " & Server.HtmlEncode(gvResults.Rows(loop1).Item("c2rdt")) & " " & Server.HtmlEncode(gvResults.Rows(loop1).Item("unitm")) & " " & Server.HtmlEncode(gvResults.Rows(loop1).Item("prdno")) & " " & Server.HtmlEncode(gvResults.Rows(loop1).Item("actsp")) & " <br>")
  36.  
  37.  
  38.             Next loop1
  39.             gridview1.DataBind()
  40.         End If
  41.  
  42.         gridview1.DataSource = mydataset.Tables("OBCOP200").DefaultView
  43.         gridview1.DataBind()
  44.         gridview1.Visible = True
Sep 11 '07
51 7961
Frinavale
9,735 Recognized Expert Moderator Expert
I suggest following the example from MSDN only instead of using the Microsoft SQL Database code, use your AS400 database code:
Expand|Select|Wrap|Line Numbers
  1.  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  2.  
  3.     ' This example uses Microsoft SQL Server and connects
  4.     ' to the Northwind sample database. The data source needs
  5.     ' to be bound to the GridView control only when the 
  6.     ' page is first loaded. Thereafter, the values are
  7.     ' stored in view state.                      
  8.     If Not IsPostBack Then
  9.  
  10.       ' Declare the query string.
  11.       Dim queryString As String = _
  12.         "Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
  13.  
  14.       ' Run the query and bind the resulting DataSet
  15.       ' to the GridView control.
  16.       Dim ds As DataSet = GetData(queryString)
  17.       If (ds.Tables.Count > 0) Then
  18.  
  19.         AuthorsGridView.DataSource = ds
  20.         AuthorsGridView.DataBind()
  21.  
  22.       Else
  23.  
  24.         Message.Text = "Unable to connect to the database."
  25.  
  26.       End If
  27.  
  28.     End If
  29.  
  30.   End Sub
  31.  
  32.   Function GetData(ByVal queryString As String) As DataSet
  33.  
  34.     ' Retrieve the connection string stored in the Web.config file.
  35.     Dim connectionString As String = ConfigurationManager.ConnectionStrings("NorthWindConnectionString").ConnectionString
  36.  
  37.     Dim ds As New DataSet()
  38.  
  39.     Try
  40.  
  41.       ' Connect to the database and run the query.
  42.       Dim connection As New SqlConnection(connectionString)
  43.       Dim adapter As New SqlDataAdapter(queryString, Connection)
  44.  
  45.       ' Fill the DataSet.
  46.       Adapter.Fill(ds)
  47.  
  48.  
  49.     Catch ex As Exception
  50.  
  51.       ' The connection failed. Display an error message.
  52.       Message.Text = "Unable to connect to the database."
  53.  
  54.     End Try
  55.  
  56.     Return ds
  57.  
  58.   End Function
  59.  
Sep 11 '07 #21
kjewell23
49 New Member
when i do the debug it still says nothing in the gridview where it states gridview1.datas ource = new data.dataview(g vResults)
Sep 11 '07 #22
kjewell23
49 New Member
Do I need to make an app code then within a dataset with my data that I need because right now the getdata is underlined. Also How do I call the function into the submit button?
Sep 11 '07 #23
kjewell23
49 New Member
How do I call the function inside the button click and do I need to make app code with dataset in it
Sep 11 '07 #24
Frinavale
9,735 Recognized Expert Moderator Expert
Do I need to make an app code then within a dataset with my data that I need because right now the getdata is underlined.
No you don't...
The reason GetData is underlined is because you probably didn't create that function.

In the example the GetData gets the DataSet and returns it.
Did you create this Function?

You do not need to make another VB file to hold this code....if that's what you're asking.

Could you please post what your code looks like now?

Also How do I call the function into the submit button?
It's the same sort of thing...
In the Sub that handles the button click you create a data source for the GridView and then Bind the GridView to that data source.
Sep 11 '07 #25
kjewell23
49 New Member
page load code
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3.         Dim Order As Integer
  4.         Order = CInt(txtOrderNumber.Text)
  5.  
  6.         If Not IsPostBack Then
  7.             Dim mysql As String = "select ordno, quano, quana, actsp from rmsfiles2.obcop200 where = " & Order
  8.  
  9.             Dim mydataset As DataSet = GetData(mysql)
  10.             If (mydataset > 0) Then
  11.                 gridview1.DataSource = mydataset
  12.                 gridview1.DataBind()
  13.             Else
  14.                 txtOrderNumber.Text = " unable to connect to the database"
  15.  
  16.             End If
  17.         End If
  18.  
button code
Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  2.  
  3.         Dim connectionString = "DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=xxxxxxxxxx;System=XXX.XXX.XXX.XXX"
  4.  
  5.  
  6.         Dim myconnection As OdbcConnection
  7.         Dim myCommand As OdbcDataAdapter
  8.         Dim mydataset As New DataSet
  9.         ' Dim gvResults As DataTable
  10.         'Dim loop1 As Integer
  11.         ' Dim numrows As Integer
  12.         Dim sql As String
  13.         Dim Order As Integer
  14.         Order = CInt(txtOrderNumber.Text)
  15.         sql = "select  line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp  from rmsfiles2.obcop200 where ordno = " & Order
  16.         Try
  17.  
  18.             myconnection = New OdbcConnection("DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=xxxxxxxxxx;System=XXX.XXX.XXX.XXX")
  19.  
  20.             myCommand = New OdbcDataAdapter(sql, myconnection)
  21.  
  22.             myCommand.Fill(mydataset)
  23.         Catch ex As Exception
  24.             txtOrderNumber.Text = "invalid order number"
  25.  
  26.         End Try
  27.  
  28.         Return
  29.         gridview1.DataSource = mydataset
  30.         gridview1.DataBind()
  31.         gridview1.Visible = True
here is my function code:
Expand|Select|Wrap|Line Numbers
  1.  Function GetData(ByVal mysql As String) As DataSet
  2.         Dim connectionString = "DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=xxxxxxxxxx;System=XXX.XXX.XXX.XXX"
  3.  
  4.  
  5.         Dim myconnection As OdbcConnection
  6.         Dim myCommand As OdbcDataAdapter
  7.         Dim mydataset As New DataSet
  8.         ' Dim gvResults As DataTable
  9.         'Dim loop1 As Integer
  10.         ' Dim numrows As Integer
  11.         Dim sql As String
  12.         Dim Order As Integer
  13.         Order = CInt(txtOrderNumber.Text)
  14.         sql = "select  line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp  from rmsfiles2.obcop200 where ordno = " & Order
  15.         Try
  16.  
  17.             myconnection = New OdbcConnection("DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=xxxxxxxxxx;System=XXX.XXX.XXX.XXX")
  18.  
  19.             myCommand = New OdbcDataAdapter(sql, myconnection)
  20.  
  21.             myCommand.Fill(mydataset)
  22.         Catch ex As Exception
  23.             txtOrderNumber.Text = "invalid order number"
  24.  
  25.         End Try
  26.  
  27.         Return mydataset
  28.     End Function
  29.  
  30.  
No you don't...
The reason GetData is underlined is because you probably didn't create that function.

In the example the GetData gets the DataSet and returns it.
Did you create this Function?

You do not need to make another VB file to hold this code....if that's what you're asking.

Could you please post what your code looks like now?



It's the same sort of thing...
In the Sub that handles the button click you create a data source for the GridView and then Bind the GridView to that data source.
Sep 11 '07 #26
kjewell23
49 New Member
This part right here is underlined like its wrong
If (mydataset > 0) Then
No you don't...
The reason GetData is underlined is because you probably didn't create that function.

In the example the GetData gets the DataSet and returns it.
Did you create this Function?

You do not need to make another VB file to hold this code....if that's what you're asking.

Could you please post what your code looks like now?



It's the same sort of thing...
In the Sub that handles the button click you create a data source for the GridView and then Bind the GridView to that data source.
Sep 11 '07 #27
nanku71
5 New Member
This part right here is underlined like its wrong
If (mydataset > 0) Then
yes that is wrong. .

you have to check the rows count to be > 0

it would be

If (mydataset.tabl es(0).rows.coun t > 0) then


hope this helps.

samir
Sep 11 '07 #28
kjewell23
49 New Member
Now its says under the function getData code is the order = cint(txtOrderNu mber.text) is invalidcastexce ption was unhandled by user code and conversion from string to type integer is not valid

What should I do here?
Sep 12 '07 #29
Frinavale
9,735 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3.         Dim Order As Integer
  4.         Order = CInt(txtOrderNumber.Text)
  5.  
  6.         If Not IsPostBack Then
  7.             Dim mysql As String = "select ordno, quano, quana, actsp from rmsfiles2.obcop200 where = " & Order
  8.  
  9.             Dim mydataset As DataSet = GetData(mysql)
  10.             If (mydataset > 0) Then
  11.                 gridview1.DataSource = mydataset
  12.                 gridview1.DataBind()
  13.             Else
  14.                 txtOrderNumber.Text = " unable to connect to the database"
  15.  
  16.             End If
  17.         End If
  18.  
There is no need to grab the DataSet in the Page Load method because your user has probably not supplied an OrderNumber until they hit the button....

This is probably why you're getting that exception about casting...you'r e probably trying to cast an empty string into an integer.


The whole point to making the GetData function is so that you can get the DataSet from anywhere in code and not have to retype everything again.


Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  2.  
  3.         Dim connectionString = "DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=xxxxxxxxxx;System=XXX.XXX.XXX.XXX"
  4.  
  5.  
  6.         Dim myconnection As OdbcConnection
  7.         Dim myCommand As OdbcDataAdapter
  8.         Dim mydataset As New DataSet
  9.         ' Dim gvResults As DataTable
  10.         'Dim loop1 As Integer
  11.         ' Dim numrows As Integer
  12.         Dim sql As String
  13.         Dim Order As Integer
  14.         Order = CInt(txtOrderNumber.Text)
  15.         sql = "select  line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp  from rmsfiles2.obcop200 where ordno = " & Order
  16.         Try
  17.  
  18.             myconnection = New OdbcConnection("DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=xxxxxxxxxx;System=XXX.XXX.XXX.XXX")
  19.  
  20.             myCommand = New OdbcDataAdapter(sql, myconnection)
  21.  
  22.             myCommand.Fill(mydataset)
  23.         Catch ex As Exception
  24.             txtOrderNumber.Text = "invalid order number"
  25.  
  26.         End Try
  27.  
  28.         Return
  29.         gridview1.DataSource = mydataset
  30.         gridview1.DataBind()
  31.         gridview1.Visible = True
Why do you have a Return on line 28 in this section of code?

I'm going to repeat myself here but...the whole point to the GetData Function is so that you don't have to retype the call to the database to get the DataSet.

I think you should change your GetData function to:

Function GetData(ByVal mysql As String, ByVal myOrderNumber As Integer)

This way you can check to make sure that the user entered an order number before trying to use it in the database call.

Expand|Select|Wrap|Line Numbers
  1.  Function GetData(ByVal mysql As String) As DataSet
  2.         Dim connectionString = "DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=xxxxxxxxxx;System=XXX.XXX.XXX.XXX"
  3.  
  4.  
  5.         Dim myconnection As OdbcConnection
  6.         Dim myCommand As OdbcDataAdapter
  7.         Dim mydataset As New DataSet
  8.         ' Dim gvResults As DataTable
  9.         'Dim loop1 As Integer
  10.         ' Dim numrows As Integer
  11.         Dim sql As String
  12.         Dim Order As Integer
  13.         Order = CInt(txtOrderNumber.Text)
  14.         sql = "select  line#, ordno, quano, quana, quans, c2rdt, unitm, prdno, actsp  from rmsfiles2.obcop200 where ordno = " & Order
  15.         Try
  16.  
  17.             myconnection = New OdbcConnection("DRIVER=Client Access ODBC Driver (32-bit);UID=ODBC;PWD=xxxxxxxxxx;System=XXX.XXX.XXX.XXX")
  18.  
  19.             myCommand = New OdbcDataAdapter(sql, myconnection)
  20.  
  21.             myCommand.Fill(mydataset)
  22.         Catch ex As Exception
  23.             txtOrderNumber.Text = "invalid order number"
  24.  
  25.         End Try
  26.  
  27.         Return mydataset
  28.     End Function
  29.  
  30.  
This is just a reminder: Please do not post the IP and Password to your database. This is sensitive information that should not be publicly shared. I have edited it out, but please don't post this information...t his is for the safety of your own computer :)
Sep 12 '07 #30

Sign in to post your reply or Sign up for a free account.

Similar topics

7
14829
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
0
4332
by: Adam Sandler | last post by:
Hello, Prior to posting I looked at http://groups.google.com/group/ microsoft.public.dotnet.framework.aspnet/browse_thread/thread/ d8d5ae243614085e/d4fd6c4a5aa56f75 http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/abb4bcc39312a388/2de51eba9a0bcfd6 Hello,
1
1748
by: MikeB | last post by:
ooh boy, I hope I'm in the right place to ask this. I'm trying to do a class project that binds controls to data sources. I have a Drop-down List that I bound to the Author column of an SQL table Articles. I then have a GridView that is supposed to react to changes in the name selected in the DDL.
2
2862
by: Steve Kershaw | last post by:
Hi, I'm working on a project in which I have a Gridview that has data. That Gridview data must be then exported to an Excel spreadsheet. I have successfully displayed the Excel spreadsheet and fill it with data using the Range.InvokeMember(...) method: Range range2 = worksheet.get_Range("A1", "L1"); Object args2 = new Object;
6
9087
by: marylipscomb | last post by:
I am using VB.NET. I am trying to connect a button so that when it is clicked the gridview pops up the data. Partial Class Switchboard Inherits System.Web.UI.Page Protected Sub btnLookup_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLookup.Load If Not Page.IsPostBack Then Dim queryString As String = "Select CompanyID As CompanyID, Company As Company, As , As , Phone As Phone, + ' ' +...
2
1262
by: mathewgk80 | last post by:
Hi all, I would like to know how can i view a grid in page load.... I dont bind any data into tht gridview.. But i want to show the grid header and footer in the page.. I am using asp.net and c#.net... Please help me...
2
4419
by: =?Utf-8?B?VmFpYmhhdg==?= | last post by:
I am trying to populate dataset from gridview but it's not working . Can anyone plz tell me how to do it..
2
2306
by: satwinder singh | last post by:
Please help me regarding how to Export the Data from DataSet or GridView into Excel sheet. Kind Regards, Satwinder singh
5
23981
by: satyabhaskar | last post by:
hi, I want to bind the data from the Dataset to GridView When I run my code I get the error The type or namespace name 'DataRows' could not be found (are you missing a using directive or an assembly reference?) I have called the following assemblies using System; using System.Data; using System.Configuration; using System.Collections; using...
1
3023
by: Vidya A | last post by:
How to bind dataset to gridview in asop.net with vb using code
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10870
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7205
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4725
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3323
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.