473,473 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting SQL Data to display in webforms

BezerkRogue
68 New Member
I have constructed a query and want the data to load in specific locations in the page when the page loads. I keep getting BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.TextBox'. when I run the page.

Here is the code I have so far:

Dim strSQL
Dim strShift
Dim strSelDate

strShift = lblShift.Text
strSelDate = lblSelDate.Text
strSQL = "SELECT * FROM Manpower_data INNER JOIN Shift ON Shift.Shift_ID = Manpower_data.Shift_ID WHERE Manpower_data.Date = '" & strSelDate & "' AND Shift.Shift = '" & strShift & "'"
Dim objConn As New Data.SqlClient.SqlConnection("Data Source=SomeServer;Initial Catalog=SomeDB;User ID=SomeUser;password=XXXXXXX;")
Dim objCmd As New Data.SqlClient.SqlDataAdapter(strSQL, objConn)
Dim objDataSet As New Data.DataSet
objCmd.Fill(objDataSet)
objConn.Open()
objConn.Close()

txtAbsent = objDataSet.Tables("Absent").ToString
txtTO = objDataSet.Tables("TO").ToString
txtHeadCount = objDataSet.Tables("HeadCount").ToString
txtStdHeadCount = objDataSet.Tables("STDHeadCount").ToString
txtMPNotes = objDataSet.Tables("Notes").ToString

What am I missing?
Oct 23 '07 #1
5 1191
Plater
7,872 Recognized Expert Expert
The error message should have been the big hint.

You have:
Expand|Select|Wrap|Line Numbers
  1. txtAbsent = objDataSet.Tables("Absent").ToString
  2. txtTO = objDataSet.Tables("TO").ToString
  3. txtHeadCount = objDataSet.Tables("HeadCount").ToString
  4. txtStdHeadCount = objDataSet.Tables("STDHeadCount").ToString
  5. txtMPNotes = objDataSet.Tables("Notes").ToString
  6.  
What you need is:
Expand|Select|Wrap|Line Numbers
  1. txtAbsent.Text = objDataSet.Tables("Absent").ToString
  2. txtTO.Text = objDataSet.Tables("TO").ToString
  3. txtHeadCount.Text = objDataSet.Tables("HeadCount").ToString
  4. txtStdHeadCount.Text = objDataSet.Tables("STDHeadCount").ToString
  5. txtMPNotes.Text = objDataSet.Tables("Notes").ToString
  6.  

However, the object you are trying to fill them with, will have a .ToString() of something like "DataTable" and not your values, you will need to pick the value from out of the table.
Oct 23 '07 #2
BezerkRogue
68 New Member
Doh.... thanks man. ur a lifesaver.
Oct 23 '07 #3
BezerkRogue
68 New Member
The error message should have been the big hint.

You have:
Expand|Select|Wrap|Line Numbers
  1. txtAbsent = objDataSet.Tables("Absent").ToString
  2. txtTO = objDataSet.Tables("TO").ToString
  3. txtHeadCount = objDataSet.Tables("HeadCount").ToString
  4. txtStdHeadCount = objDataSet.Tables("STDHeadCount").ToString
  5. txtMPNotes = objDataSet.Tables("Notes").ToString
  6.  
What you need is:
Expand|Select|Wrap|Line Numbers
  1. txtAbsent.Text = objDataSet.Tables("Absent").ToString
  2. txtTO.Text = objDataSet.Tables("TO").ToString
  3. txtHeadCount.Text = objDataSet.Tables("HeadCount").ToString
  4. txtStdHeadCount.Text = objDataSet.Tables("STDHeadCount").ToString
  5. txtMPNotes.Text = objDataSet.Tables("Notes").ToString
  6.  

However, the object you are trying to fill them with, will have a .ToString() of something like "DataTable" and not your values, you will need to pick the value from out of the table.
How do I do this with this code? I get the expected Object reference not set to an instance of an object error message.
Oct 23 '07 #4
Plater
7,872 Recognized Expert Expert
This line:
Expand|Select|Wrap|Line Numbers
  1. objDataSet.Tables("Absent")
  2.  
Is looking for a table called "Absent" in your dataset. I am going to guess you want a column by that name?

You will need to get at your table, there is probably only one table:
Expand|Select|Wrap|Line Numbers
  1. DataTable dt=objDataSet.Tables[0];
  2.  
And then you will need the row, is there only going to be one row?
Expand|Select|Wrap|Line Numbers
  1. DataRow dr=dt.Rows[0];
  2.  
Then from THAT you can get your columns
Expand|Select|Wrap|Line Numbers
  1. dr["Absent"].ToString()
  2.  

You should be able to condense down if you want:
Expand|Select|Wrap|Line Numbers
  1. objDataSet.Tables[0].Rows[0]["Absent"].ToString();
  2.  
Oct 23 '07 #5
BezerkRogue
68 New Member
This line:
Expand|Select|Wrap|Line Numbers
  1. objDataSet.Tables("Absent")
  2.  
Is looking for a table called "Absent" in your dataset. I am going to guess you want a column by that name?

You will need to get at your table, there is probably only one table:
Expand|Select|Wrap|Line Numbers
  1. DataTable dt=objDataSet.Tables[0];
  2.  
And then you will need the row, is there only going to be one row?
Expand|Select|Wrap|Line Numbers
  1. DataRow dr=dt.Rows[0];
  2.  
Then from THAT you can get your columns
Expand|Select|Wrap|Line Numbers
  1. dr["Absent"].ToString()
  2.  

You should be able to condense down if you want:
Expand|Select|Wrap|Line Numbers
  1. objDataSet.Tables[0].Rows[0]["Absent"].ToString();
  2.  
Thanks. That's working great.
Oct 23 '07 #6

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

Similar topics

0
by: Jim | last post by:
I need some help getting started with a .NET web project for a commercial site. I am new to .NET and my understanding of some (but not all) of its concepts is a little sparse. I apologize for the...
0
by: Jim | last post by:
This si a repost, I apologize but perhaps my original inquiry got buried under all the usenet spam... I need some help getting started with a .NET web project for a commercial site. I am new to...
3
by: Netserver | last post by:
Hi have a question hope there is a simple answer. I want to enter data in to 2 arrays from several webforms in project and be able to recall that data from any of the webforms, other then using a...
2
by: Piotr Karwatka | last post by:
Hi! I have a little problem an qeustion. In .NET Windows Forms I can do something like that: - i have forms - Form1 Form2, on first form i have TextBox1 control on 2nd form I have Button1...
1
by: basulasz | last post by:
May be it is a bit easy question but i don't know the way to display data in bounded colums. I get data from DB with a datareader, and I want to display them on bounded colums. I dont want to...
4
by: Jakob Lithner | last post by:
I just read an interesting article on Data Sources in Visual Studio 2005: http://msdn.microsoft.com/vbasic/default.aspx?pull=/library/en-us/dnvs05/html/newdtastvs05.asp It was an eye opener on...
10
by: Martin Hughes | last post by:
Hi guys, I was wondering if anyone could give me some advice. I am looking to develop an ASP.NET application that will enable several workstations to access real time telemetry data received...
3
by: KimberlyLord | last post by:
I have created a report and subreport in VB/ASP.NET. The report works fine but the subreport will not display. The subreport, when displayed as a standalone report, works fine. But when viewed as a...
2
by: =?Utf-8?B?R3lhbmVuZHJh?= | last post by:
I am using Ajax control(Update Panel) in my web page(ASP.Net 2.0) and putting Report Viewer(Sql Server Reporting Services 2005) Control in it. When I am displaying any report it is coming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.