473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Reading an SQL database

Des
I am new to .NET so this code will not be the best. I need to read
fields from a single record and place them into individual variables.
What I have is this and the error is

BC30311: Value of type 'System.Data.DataColumn' cannot be converted to
'String'.

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<%
ID = request("ProdID")

Dim strConn as String = ConfigurationSettings.AppSettings("Thermos")
Dim objConn as new SqlConnection(strConn)

dim strItem as String = "SELECT * FROM Products WHERE ProductID = " &
ID

dim Adapter as new SqlDataAdapter(strItem,objConn)
dim DataSet as new DataSet()
Adapter.Fill(DataSet, "ITEM")

Dim Description as String
Description = DataSet.Tables("ITEM").Columns("Description")
%>
<html> ..... </html>

Any help on this one please

Desmond.

Feb 22 '06 #1
7 1473
Hi,

I believe ID is an integer value

change the statement from
dim strItem as String = "SELECT * FROM Products WHERE ProductID = " &
ID.
to
dim strItem as String = "SELECT * FROM Products WHERE ProductID = " &
ID.ToString()

This should work..

Vinu

"Des" <de*********@aol.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I am new to .NET so this code will not be the best. I need to read
fields from a single record and place them into individual variables.
What I have is this and the error is

BC30311: Value of type 'System.Data.DataColumn' cannot be converted to
'String'.

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<%
ID = request("ProdID")

Dim strConn as String = ConfigurationSettings.AppSettings("Thermos")
Dim objConn as new SqlConnection(strConn)

dim strItem as String = "SELECT * FROM Products WHERE ProductID = " &
ID

dim Adapter as new SqlDataAdapter(strItem,objConn)
dim DataSet as new DataSet()
Adapter.Fill(DataSet, "ITEM")

Dim Description as String
Description = DataSet.Tables("ITEM").Columns("Description")
%>
<html> ..... </html>

Any help on this one please

Desmond.

Feb 22 '06 #2
Des
ID is not the Problem ID is an integer as it is an auto number. The
problem is with

Dim Description as String
Description = DataSet.Tables("ITEM").Columns("Description")

BC30311: Value of type 'System.Data.DataColumn' cannot be converted to
'String'.

Feb 22 '06 #3
HI
Here is the reason why its not working


DataTable userTable = new DataTable();

DataSet ds = new DataSet();

userTable.Columns.Add("userID", Type.GetType("System.Int32"));

userTable.Columns.Add("username", Type.GetType("System.String"));

DataRow userRow = userTable.NewRow();

userRow["userID"] = 1;

userRow["username"] = "Peter";

userTable.Rows.Add(userRow);

userRow = userTable.NewRow();

userRow["userID"] = 2;

userRow["username"] = "Paul";

userTable.Rows.Add(userRow);

userRow = userTable.NewRow();

userRow["userID"] = 3;

userRow["username"] = "Mary";

userTable.Rows.Add(userRow);

ds.Tables.Add(userTable);

MessageBox.Show(ds.Tables[0].Columns["username"] ); /**Compile error **/

/*Change the above code and try*/

MessageBox.Show(ds.Tables[0].Columns["username"].ToString() );

So change

Description = DataSet.Tables("ITEM").Columns("Description")
to

Description = DataSet.Tables("ITEM").Columns("Description").ToSt ring()

Cheers
Vinu

"Des" <de*********@aol.com> wrote in message news:11*********************@g14g2000cwa.googlegro ups.com...
ID is not the Problem ID is an integer as it is an auto number. The
problem is with

Dim Description as String
Description = DataSet.Tables("ITEM").Columns("Description")

BC30311: Value of type 'System.Data.DataColumn' cannot be converted to
'String'.

Feb 22 '06 #4
Des
No this isn't right I do not need to create a new table. I already have
one
ProdID is an auto number
Description is Text "Mary had a little lamb" why do I have to convert
text to text, if Description is a text field already.

Description = DataSet.Tables("ITEM").Columns("Description").ToSt ring()

Feb 22 '06 #5
Hi

Just change and try...let see whether it generating an error or not...i am
sure it won't try it...

Description = DataSet.Tables("ITEM").Columns("Description")
to

Description = DataSet.Tables("ITEM").Columns("Description").ToSt ring()

Vinu

"Des" <de*********@aol.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
No this isn't right I do not need to create a new table. I already have
one
ProdID is an auto number
Description is Text "Mary had a little lamb" why do I have to convert
text to text, if Description is a text field already.

Description = DataSet.Tables("ITEM").Columns("Description").ToSt ring()

Feb 22 '06 #6
Hi
The reason its not working is

statement DataSet.Tables("ITEM").Columns("Description") return DataColumn.
You can't assign DataColumn to String. That's why you need to use ToString
to convert to a string.

Vinu


"Des" <de*********@aol.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
No this isn't right I do not need to create a new table. I already have
one
ProdID is an auto number
Description is Text "Mary had a little lamb" why do I have to convert
text to text, if Description is a text field already.

Description = DataSet.Tables("ITEM").Columns("Description").ToSt ring()

Feb 22 '06 #7
Hi,

DataSet.Tables("ITEM").Columns("Description")

will not give you the coumn value, insted it will return the column name.To
get the column value

DataSet.Tables("ITEM").Rows[rowindex][columindex].ToString()

vinu

"Des" <de*********@aol.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
No this isn't right I do not need to create a new table. I already have
one
ProdID is an auto number
Description is Text "Mary had a little lamb" why do I have to convert
text to text, if Description is a text field already.

Description = DataSet.Tables("ITEM").Columns("Description").ToSt ring()

Feb 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dariusz | last post by:
I have PHP code (below) which reads data from a MySQL format database. The problem I am having is trying to find out when the last ID entry was made. When the script is executed, the $gbID is...
1
by: Google Mike | last post by:
Tell me if this can be done, and if I have a misconception here. I am writing an app that will be served up in an app farm, and therefore I need to move the session information to the client, not...
2
by: Dariusz | last post by:
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem...
0
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it...
7
by: John Pote | last post by:
Hello, help/advice appreciated. Background: I am writing some web scripts in python to receive small amounts of data from remote sensors and store the data in a file. 50 to 100 bytes every 5 or...
2
by: Ed | last post by:
Hope someone can help me out... I have been tasked to read some image data from an sql database and save the files to flat files. OK, sounds easy as I'v used BLOBs before. But this is an old...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
0
by: Andrea | last post by:
Hi, I've a problem reading a field containing a crypted string. I read the field via JDBC but when I decrypt the string I obtain a sequence of strange characters (if I output them I obtain a...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
1
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello All, I am trying to read an Excel spreadsheet (xls) programmatically. I have used the ODBC database route and have opened the Excel spreadsheet and then using a 'CRecordset', I read each...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
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...

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.