What am I doing wrong with this? (DataRow)

V

vbMark

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();
}
}
 
M

Marina

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.
 
V

vbMark

@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 said:
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();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top