reading just one cell out of a dataset.

N

N. Okan Guney

Hello,


How could I read just one cell out of a dataset?

I have a query returing a 3 x 3 table.

a b c
d e f
x y z


I need the value of "f" ([2][2] ) from the table. How could I do this using
C#?

Thanks in advance,



System.Data.DataSet onhand(string partno) {

string connectionString = "server=\'sql01\'; trusted_connection=true;
database=\'data03\'";

System.Data.IDbConnection dbConnection = new
System.Data.SqlClient.SqlConnection(connectionString);

string queryString = "SELECT [inmast].[fonhand] FROM [inmast] WHERE
(([inmast].[fpartno] = \'"+partno+"\') AND" + " ([inmast].[fcstscode] =
\'A\'))";

System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();

dbCommand.CommandText = queryString; dbCommand.Connection = dbConnection;

System.Data.IDbDataAdapter dataAdapter = new
System.Data.SqlClient.SqlDataAdapter();

dataAdapter.SelectCommand = dbCommand; System.Data.DataSet dataSet = new
System.Data.DataSet();
dataAdapter.Fill(dataSet);
return dataSet;
}
 
S

S. Justin Gengo

DataSet.Tables("TableName").Rows(1)(2)

Where Rows(Zero Based Row Number Index)(Zero Based Column Index)

Or Rows(1)("ColumnNameAsString")

Hope this helps.

Justin
 
J

Jeff Ptak

Try this:

F_Value = dataset.Tables[0].Rows[1].ItemArray[5];

Or

F_Value = dataset.Tables[0].Rows[1]["FieldNameForF"];

You may have to cast the value to the correct datatype,
but this should get you started.

HTH,

Jeff Ptak

-----Original Message-----

Hello,


How could I read just one cell out of a dataset?

I have a query returing a 3 x 3 table.

a b c
d e f
x y z


I need the value of "f" ([2][2] ) from the table. How could I do this using
C#?

Thanks in advance,



System.Data.DataSet onhand(string partno) {

string connectionString = "server=\'sql01\'; trusted_connection=true;
database=\'data03\'";

System.Data.IDbConnection dbConnection = new
System.Data.SqlClient.SqlConnection(connectionString);

string queryString = "SELECT [inmast].[fonhand] FROM [inmast] WHERE
(([inmast].[fpartno] = \'"+partno+"\') AND" + " ([inmast]. [fcstscode] =
\'A\'))";

System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();

dbCommand.CommandText = queryString; dbCommand.Connection = dbConnection;

System.Data.IDbDataAdapter dataAdapter = new
System.Data.SqlClient.SqlDataAdapter();

dataAdapter.SelectCommand = dbCommand;
System.Data.DataSet dataSet = new
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,235
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top