Hi friends,
Please can you`ll help me
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Datta KharadRank #2,135 · 668 reputationPosted Nov 8, 2011, 12:53 AM EST
Describe your question in detail i,e what do you want?
Nethra R SRank #6,347 · 269 reputationPosted Nov 8, 2011, 1:17 AM EST
How to write a method that returns a datareader object, same way to return dataset,datatable object. Can you tell me how to write the code for that?
Datta KharadRank #2,135 · 668 reputationPosted Nov 8, 2011, 2:46 AM EST
You can try this code...
private void button2_Click(object sender, EventArgs e)
{
DataSet ds=new DataSet();
DataSet dsData = new DataSet();
DataTable dt=new DataTable();
DataTable dtData = new DataTable();
SqlDataReader dr=null;
SqlDataReader drData = null;
object objData;
objData = MethodCall(ds, "DATASET");
dsData = (DataSet)objData;
objData = MethodCall(dt, "DATATABLE");
dtData = (DataTable)objData;
objData = MethodCall(dr, "DATAREADER");
drData = (SqlDataReader)objData;
}
private object MethodCall(object obj, string senderType)
{
DataSet dsTemp=new DataSet();
DataTable dtTemp = new DataTable();
SqlDataReader drTemp ;
object resObj=null;
if (senderType == "DATASET")
{
dsTemp = (DataSet)obj;
//Here your code
//==========
resObj = dsTemp;
}
else if(senderType=="DATATABLE")
{
dtTemp = (DataTable)obj;
//Here your code
//==========
resObj = dtTemp;
}
else if (senderType == "DATAREADER")
{
drTemp = (SqlDataReader)obj;
//Here your code
//==========
resObj = drTemp;
}
return resObj;
}
If you got correct solution then mark as Accepted Answer.
Sam HobbsRank #107 · 20.5K reputationPosted Nov 8, 2011, 9:19 AM EST