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

What am I doing wrong with this? (DataRow)

When I call the below code what I get returned
is the string "System.Data.DataRow"

I don't understand how this works. What am I doing wrong?

private string GetData(string strQuery)
{
SqlConnection sqlCN = new SqlConnection(CONNECTION_INFO);
SqlDataAdapter sqlDA = new SqlDataAdapter(strQuery, sqlCN);

try
{
sqlCN.Open();

DataSet DS = new DataSet();

sqlDA.Fill(DS);

System.Data.DataRow drDataRow;
drDataRow = DS.Tables[0].Rows[0];

DS.Dispose();
sqlCN.Close();

return drDataRow.ToString();
}
catch (SqlException sqlExcp)
{
return "Error: " + sqlExcp;
}
finally
{
sqlCN.Dispose();
sqlDA.Dispose();
}
}
Nov 16 '05 #1
2 2391
The ToString method of the datarow just returns the name of the class. So
you get what you are supposed to get when calling this method.

If you want the contents of the datarow, you have to create that string
yourself by iterating through the contents of the row.

"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
When I call the below code what I get returned
is the string "System.Data.DataRow"

I don't understand how this works. What am I doing wrong?

private string GetData(string strQuery)
{
SqlConnection sqlCN = new SqlConnection(CONNECTION_INFO);
SqlDataAdapter sqlDA = new SqlDataAdapter(strQuery, sqlCN);

try
{
sqlCN.Open();

DataSet DS = new DataSet();

sqlDA.Fill(DS);

System.Data.DataRow drDataRow;
drDataRow = DS.Tables[0].Rows[0];

DS.Dispose();
sqlCN.Close();

return drDataRow.ToString();
}
catch (SqlException sqlExcp)
{
return "Error: " + sqlExcp;
}
finally
{
sqlCN.Dispose();
sqlDA.Dispose();
}
}

Nov 16 '05 #2
"Marina" <so*****@nospam.com> wrote in news:#dwhNRBSEHA.3140
@tk2msftngp13.phx.gbl:

That was it. Thanks!
The ToString method of the datarow just returns the name of the class. So you get what you are supposed to get when calling this method.

If you want the contents of the datarow, you have to create that string
yourself by iterating through the contents of the row.

"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
When I call the below code what I get returned
is the string "System.Data.DataRow"

I don't understand how this works. What am I doing wrong?

private string GetData(string strQuery)
{
SqlConnection sqlCN = new SqlConnection(CONNECTION_INFO);
SqlDataAdapter sqlDA = new SqlDataAdapter(strQuery, sqlCN);

try
{
sqlCN.Open();

DataSet DS = new DataSet();

sqlDA.Fill(DS);

System.Data.DataRow drDataRow;
drDataRow = DS.Tables[0].Rows[0];

DS.Dispose();
sqlCN.Close();

return drDataRow.ToString();
}
catch (SqlException sqlExcp)
{
return "Error: " + sqlExcp;
}
finally
{
sqlCN.Dispose();
sqlDA.Dispose();
}
}



--
http://www.vbmark.com/
A good place to start.
Nov 16 '05 #3

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

Similar topics

2
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
1
by: J | last post by:
Further to my post below, I've tried to replicate the error in a hope that I'm definately doing something wrong, and it's not my code. The following DOES work. Private Sub Page_Init(ByVal...
3
by: shin | last post by:
hi i am trying to output an image which i have in a database. but this gives me errors byte Picture; Picture = (dr); //cannot convert from object to byte Response.Buffer=true;
1
by: Shapper | last post by:
Hello, I am trying to create a dataset by adding rows to it in a For loop: Dim dsNews As DataSet = New DataSet() Dim row As DataRow = dsNews.Tables(0).NewRow() dsNews.Tables.Add...
8
by: cjobes | last post by:
Hi all, The code below is part of a form where I would like the user to make selections from a table. The data is brought into the form from another form with: Public WriteOnly Property...
12
by: Gary Paris | last post by:
I have enclosed the sample code that I created. I want to read in employee data, and modify a few fields. I have tried to globally declare the objects that I need but I still am having problems. ...
6
by: timbobd | last post by:
I have a Windows form that displays a database table in a DataGrid. When you click on a row, the row's values get copied to bound TextBoxes below, and when the "Save" button is clicked the database...
4
by: Daniel | last post by:
What's wrong with this code? 1 Dim parentRow, childRow as DataRow 2 3 For i = 0 To mainDataTable.Rows.Count - 1 4 parentRow = mainDataTable.Rows(i) 5 childRow =...
16
by: SLIMSHIM | last post by:
Hi, I"m new to c# and .net. I wrote a small program to add rows to an access table. the program goes thru the motions but the data never gets there. here is my code. I am intentionaly not using...
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: 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: 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
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...
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...

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.