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

Strings Strings Strings from sql ds.

New to C#. Ive got my data coming out in the form of a datagrid. I want to
take my data which comes from a "text" field inside sql server 2000.

Ive tried forcing the data into a string as:

string xyz= ds.Tables.["news"].Columns.["article"].ToString();
and
richTextBox1.DataBindings.Add( new Binding ("Text",ds,"news.article"));

but come up with an object type.

Must be a simple to gather data and place it into a string...

How can i get the data which is in Column "article" and place it into string
xyz?

Id like to bypass using the datagrid if at all possible..I imagine there is
a myriad of ways to display data??
Thanks for any help/pointers.

ccma

Nov 16 '05 #1
5 2830
Hello!
string xyz= ds.Tables.["news"].Columns.["article"].ToString();


This simple gets the object representation of the "article" column in the
"news" table. Getting data from the DataSet (ds) is a matter of:

1. Referencing the correct DataTable ("news")
2. Referencing the correct DataRow from the DataTable
3. Referencing the correct DataColumn from the DataRow

Usually you do a foreach iteration on a DataTable, accessing the DataRows
with a variable and using that to display some data.

foreach (DataRow row in ds.Tables["news"])
{
string xyz = row["article"].ToString();
// You could leave the ToString() part out if the column is a string
datatype
}

When databinding, you associate a databindable object with a datasource like
this:

// Associate datasource
dataGrid.DataSource = ds.Tables["news"];

// Ask the datagrid to start databinding to the datasource
dataGrip.DataBind();

Hopefully, this should get you started. If not, let us know.

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #2
"Anders Borum" wrote:
Hello!


Salut!

Im using:

foreach (DataRow row in ds.Tables["it_daily_news"])
{
string xyz = row["article"].ToString();
}

where it_daily_news is the table used in the sql query:
string query = "select TOP 1 article from it_daily_news order by dateval
desc";

I
Unfortunately this bails on build with a reference to:

Form1.cs(93): foreach statement cannot operate on variables of type
'System.Data.DataTable' because 'System.Data.DataTable' does not contain a
definition for 'GetEnumerator', or it is inaccessible

eep.

Thanks for the help!

Nov 16 '05 #3
Hello!

It was my impression that an enumerator from the DataTable was able to
enumerate the rows, but this was not the case. You simply have to change
your foreach to this:

// Notice the .Rows addition ..

foreach (DataRow row in ds.Tables["it_daily_news"].Rows)
{
string xyz = row["article"].ToString();
}

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #4
Fantastic. I am at home now. Tomorrow I will apply what you have written.
Thanks for the replys.

Ive been using php and building web applications , so I am familiar with
concepts of c#, but the syntax is confusing =>
Thanks again Anders.

"Anders Borum" wrote:
Hello!

It was my impression that an enumerator from the DataTable was able to
enumerate the rows, but this was not the case. You simply have to change
your foreach to this:

// Notice the .Rows addition ..

foreach (DataRow row in ds.Tables["it_daily_news"].Rows)
{
string xyz = row["article"].ToString();
}

--
venlig hilsen / with regards
anders borum
--

Nov 16 '05 #5
Hello!
Ive been using php and building web applications , so I am familiar with
concepts of c#, but the syntax is confusing =>
It's just a matter of getting to know the different constructs of the
language and the interfaces of the different types you work with. It could
have been the case that your foreach would have worked, if the BCL (base
class library) team had implemented an enumerator on the DataTable that
iterated the rows collection.
Thanks again Anders.


That's what we're here for ..

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #6

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

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
25
by: Rainmaker | last post by:
Hi, Can anyone tell me an efficient algorithm to sort an array of strings? Keep in mind that this array is HUGE and so the algorithm should me efficient enough to deal with it. Thanks
6
by: Broeisi | last post by:
Hello, I wrote the tiny progam below just to understand arrays and strings better. I have 2 questions about arrays and strings in C. 1. Why is it that when you want to assign a string to an...
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
19
by: pkirk25 | last post by:
I wonder if anyone has time to write a small example program based on this data or to critique my own effort? A file called Realm List.html contains the following data: Bladefist-Horde...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.