473,386 Members | 1,610 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,386 software developers and data experts.

Setting variables to a value in a dataset.

I'm new to C# but learning quickly.

What i have is a prog that does a connection to a database and pulls in a
(untyped) dataset during runtime. I have some bound data to textboxes etc and
those work fine, but when i attempt to set some dataset values to variables,
it throws the prog to catch (using try and catch) By the way, None of this
was ceated with the VS wizards.

I got the command from MSDN i thought i needed
string s = (string) ds.Tables["myTable"].Rows[0]["mycolumn"];

I would like a single value from the dataset to be set to a variable, but i
guess I would also be happy with the entire row in an array perhaps.

Everything in the DB that iu'm pulling into the dataset are strings
I have found many other postings on this but have not had any luck. Does
anyone have any ideas? Thanks in advance.
Nov 17 '05 #1
2 4951
On Fri, 1 Apr 2005 13:15:04 -0800, Robert
<Ro****@discussions.microsoft.com> wrote:
I'm new to C# but learning quickly.

What i have is a prog that does a connection to a database and pulls in a
(untyped) dataset during runtime. I have some bound data to textboxes etc and
those work fine, but when i attempt to set some dataset values to variables,
it throws the prog to catch (using try and catch) By the way, None of this
was ceated with the VS wizards.

I got the command from MSDN i thought i needed
string s = (string) ds.Tables["myTable"].Rows[0]["mycolumn"];

I would like a single value from the dataset to be set to a variable, but i
guess I would also be happy with the entire row in an array perhaps.

Everything in the DB that iu'm pulling into the dataset are strings
I have found many other postings on this but have not had any luck. Does
anyone have any ideas? Thanks in advance.


What kind of exception do you get?

Try to split the statement into multiple statements like:

DataTable dtab = ds.Tables["myTable"];
DataRow drow = dtab.Rows[0];
DataColumn dcol = drow["mycolumn"];
string s = (string)dcol;

Then debug and see where the exception iks thrown.

--
Ludwig Stuyck
http://www.coders-lab.net
Nov 17 '05 #2


"Ludwig Stuyck" wrote:
On Fri, 1 Apr 2005 13:15:04 -0800, Robert
<Ro****@discussions.microsoft.com> wrote:
I'm new to C# but learning quickly.

What i have is a prog that does a connection to a database and pulls in a
(untyped) dataset during runtime. I have some bound data to textboxes etc and
those work fine, but when i attempt to set some dataset values to variables,
it throws the prog to catch (using try and catch) By the way, None of this
was ceated with the VS wizards.

I got the command from MSDN i thought i needed
string s = (string) ds.Tables["myTable"].Rows[0]["mycolumn"];

I would like a single value from the dataset to be set to a variable, but i
guess I would also be happy with the entire row in an array perhaps.

Everything in the DB that iu'm pulling into the dataset are strings
I have found many other postings on this but have not had any luck. Does
anyone have any ideas? Thanks in advance.
What kind of exception do you get?

Try to split the statement into multiple statements like:

DataTable dtab = ds.Tables["myTable"];
DataRow drow = dtab.Rows[0];
DataColumn dcol = drow["mycolumn"];
string s = (string)dcol;

Then debug and see where the exception iks thrown.

--
Ludwig Stuyck
http://www.coders-lab.net

Thanks for the help.

Now, the third line of code you gave me gives me this error.

Cannot implicitly convert type 'object' to 'System.Data.DataColumn'
I'll research that and try and find out what I'm doing wrong.

Nov 17 '05 #3

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

Similar topics

8
by: Wayne Wengert | last post by:
I am trying to build a VB.NET Windows application in which I want to create an XML file from data collected from the user and stored in arrays. I am looking for any pointers to information on how...
2
by: WhiskyRomeo | last post by:
I have a bound textbox (bindings are set at design time) to a dataset column. Sometimes the value of this textbox must be set so that the underlying database field gets updated to null when using...
7
by: danny | last post by:
Hello everyone, How can I go about setting a number of variables using a table which will have the variable names to be declared in one table. The data to be assigned will reside in another. As...
2
by: Stuart | last post by:
Hi there I am using several processes within an .asp application that store variables in to session - typically: Session("UniqueName") = Value I am having a hell of a time overwriting the...
7
by: fisab | last post by:
I apologise in advance for such a basic question, but I'm hoping someone will take the time to answer my question. In my code I define a Dataset : Partial Class Default_aspx Dim dsExcel As...
3
by: Matthew | last post by:
I'm a bit new to VB, so please be understanding. I would like to have several variables that are remembered even when the user closes the program and re-opens it. The following seems to describe...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
8
by: Andrus | last post by:
..NET 2 Winforms application. How to create new setting and set it default value in userSettings section of app.config file or overwrite existing setting value ? I found code below in this list...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.