I have a function which have return type DataRow and the parameters for the fucntion
are the parameters for the stored procedure.

I have to execute the Stored Procedure with given parameters and populate the datarow so that
the return will be the populated DataRow with the output of the stored procedure.

Again I have to retrieve data from the same datarow, perform some calculations in another function
which is going to use above datarow values, and give result in double or int datatype.

I have executed the Stored Procedure and now i m trying to store the data in the datarow
so that I can further retrieve it.

do anybody have idea how to insert and retreive data from DataRow in above case.

Thanks in advance,

Recommended Answers

All 8 Replies

I'm not sure if this is your question but are you just trying to read and write data to the data row? If so, then just do this:

To Read:

int myIntVar = (int)myDataRow["ColumnName1"];

string myStringVar = (string)myDataRow["ColumnName2"];

etc...

To Write:

myDataRow["ColumnName1"] = myIntVar;
myDataRow["ColumnName2"] = myStringVar;

etc...

Off the top of my head I can't remember which cases are which, but some types need to use the Convert methods instead of the straight casts.

You can also try and use nullable types (assuming you are using .NET 2.0 and up) - instead of declaring your variables like:

int myFieldValue ....

you can simply do the following:

int? myFieldValue ...

I am calling a stored procedure which returns some parameters and storing these parameters in a datarow say "drSPParameter", in a function say "InsertParameter".
Now this is one function, now I have another function where I want to use some of these parameters i.e. want to extract some parameters from datarow in another function.
i.e. retrieving data from these function's datarow parameter.Consider this function name as
"RetrieveParameter"

How can I do this?

Hi Can you please provide me source i will guide to solve it

For Retrieving records from data row use the following code

where ds is the dataset

foreach(DataRow dr in ds.Tables[0].Rows)
{
            c1  = Convert.ToString(dr["ColumeName1"]);
            c2 = Convert.ToString(dr["ColumeName2"]);
            c3 = Convert.ToString(dr["ColumeName3"]);
 }

private DataRow FetchSPParameter(string a,string b, int i)
{
drSPParameter=function to get the FirstRow from datatable of dataset("FetchSPParameter", "SPParameter", parameters);
}

where drSPParameter is the datarow where i m storing the output of the function which gets the datarow from the datatable "SPParameter" of the dataset , the second parameter
and parameters are the parameters from the fucntion to the stored procedure

"FetchSPParameter" is the stored procedure

and function returns "drSPParameter" datarow

I want to use some parameters from "drSPParameter" datarow in another function
say
private double Calculatethis()

which accepts some parameters of the datarow "drSPParameter"
My question is how can i use it in private double Calculatethis()?

Let Assume that your firstrow funcation returns a row of an employee Table

Retrive the records

int c1 = Convert.ToInt32(dr["EMPID"]);
string c2 = Convert.ToString(dr["EMPNAME"]);
double c3 = Convert.ToDouble(dr["Sal"]);

pass the variable c3 as paramter to your calculatethis function

private double Calculatethis(double c3)
{
double bonus=c3 +(c3*25/100)
return bonus
}

please letme know you finding difficult to retrieve a datarow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.