Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

This code is correct or not ,at the time of return the value my dataset shows the empty.
DataSet dset;
        SqlDataAdapter dAdapter;
        SqlCommand command = new SqlCommand();
        //string deptno = "";
        try
        {
            con.Open();
            dAdapter = new SqlDataAdapter(spNameForXlUpload, con);
            command.CommandType = CommandType.StoredProcedure;
            command.Connection = con;
            command.CommandText = spNameForXlUpload;
            command.Parameters.Add(new SqlParameter("@XMLItemsDoc", xmlDoc.Trim()));
            
            command.ExecuteNonQuery();
            
            dAdapter.SelectCommand = command;
            dset = new DataSet();
            dAdapter.Fill(dset);
            return dset;
        }


can anyone help me to do this


Thanks..
Posted
Comments
bbirajdar 27-Aug-12 5:47am    
Does your SP return anything? How can we guess unless you show us what your SP does ? You are using ExecuteNonQuery() which returns only number of rows affected.. Your whole code and logic seems to be a mess..
[no name] 27-Aug-12 6:08am    
i chked my SP its ok
bbirajdar 27-Aug-12 6:32am    
ok
[no name] 27-Aug-12 6:23am    
my SP returns recordset like this <NEWDATASET> <Table1> <eno>40
<ename>IT </Table1> <Table1> <eno>50 <ename>S/w </Table1> <Table1> <eno>60 <ename>Civil </Table1> <NEWDATASET>
but still now my dataset shows empty
bbirajdar 27-Aug-12 6:32am    
ok

Have a look on the Below code

C#
Public DataSet GetDataformSP()
{
string connString = "<your connection="" string="">";
string sql = "name of your sp";

SqlConnection conn = new SqlConnection(connString);

try {
   SqlDataAdapter da = new SqlDataAdapter();
   da.SelectCommand = new SqlCommand(sql, conn);
   da.SelectCommand.CommandType = CommandType.StoredProcedure;
//Add parameters here as you stated in your question.    
//command.Parameters.Add(new SqlParameter("@XMLItemsDoc", xmlDoc.Trim()));

   DataSet ds = new DataSet();   
   da.Fill(ds, "result_name");

  return ds;

} catch(Exception e) {
   Console.WriteLine("Error: " + e);
} finally {
   conn.Close();
}
}</your>
 
Share this answer
 
Hi,
If your sp returns recordset then only this will work. Otherwise you can use ExecuteNoneQuery function of command object. Try this:
C#
DataSet dset = null;
SqlDataAdapter dAdapter;
//string deptno = "";
try
{
    con.Open();
    SqlCommand command = new SqlCommand(spNameForXlUpload, con);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("@XMLItemsDoc", xmlDoc.Trim()));
    dAdapter = new SqlDataAdapter(command);        
    dset = new DataSet();
    dAdapter.Fill(dset);
    return dset;
}



All the best.
--Amit
 
Share this answer
 
v2
Comments
[no name] 27-Aug-12 6:17am    
my SP returns recordset like this <NEWDATASET> <Table1> <eno>40

<ename>IT </Table1> <Table1> <eno>50 <ename>S/w </Table1> <Table1> <eno>60 <ename>Civil </Table1> <NEWDATASET>
but still now my dataset shows empty
bbirajdar 27-Aug-12 6:32am    
ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900