Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After execution result is coming in two select statement. How can get in two different data table by c#?


using (SqlConnection con = new SqlConnection(sqlConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "Exec SPSearchInvoiceList_rjt " + _customerID + "," + _ProjectInchargeID + "," + _projectID +
"," + _invoiceType + ",'" + _projectTypes + "'," + _invoiceAmount + ",'" + _invoiceCode +
"'," + _invoiceStatusID + ",'" + _invoiceDateFrom + "','" + _invoiceDateTo + "','" +
_invoiceRevisedDateFrom + "','" + _invoiceRevisedDateTo + "','" + _invoiceRaiseDateFrom +
"','" + _invoiceRaiseDateTo + "'," + Convert.ToInt32(PageIndex) + 1 + "," + pageSize;
cmd.Connection = con;
con.Open();
var datareader = cmd.ExecuteReader();
con.Close();
}
}

What I have tried:

I am trying to do it as above.I am unable to get records but i am able to get data once i execute commandtext in sql server. Please help.
Posted
Updated 16-Aug-16 22:22pm
Comments
Karthik_Mahalingam 17-Aug-16 4:16am    
post the stored procedure code.

1 solution

use SqlDataAdapter[^]

C#
cmd.Connection = con;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);

DataTable dt1 = ds.Tables[0]; // first select result
DataTable dt2 = ds.Tables[1]; // second select result


note: your code is vulnerable to SQL Injection[^] attacks
always use Parameterized queries to prevent SQL Injection Attacks in SQL Server[^]
 
Share this answer
 
Comments
.net bigner 17-Aug-16 5:58am    
Thanks..It is working fine.
Karthik_Mahalingam 17-Aug-16 6:01am    
welcome:)

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