urgent asp.net Help:

G

Guest

i am posting below code i am not sure how to call parametrized store
procedure and fill the grid.
....
I have store procedure which pull the info from sql server 2005 using
asp.net 1.1... that proc accept two parameters .
any body has any idea how to do that thing using dataset ....
thanks
public DataSet GetCustByDate(int MonthNo,string YearNo)
{
strSQL="dbo.sp_GetCust " + MonthNo.ToString() + " , " + YearNo;

SqlConnection conn = this.GetConnection();
conn.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(strSQL, conn);
DataSet ds = new DataSet();
myCommand.Fill(ds, strSQL);
conn.Close();

return ds;

}
 
G

Guest

Amjad,
This is the WRONG way to use ADO.NET to make a stored procedure call!
You are using the Language path through SQL Server, and you want to use the
RPC path instead.

1) Create a SqlCommand object, set it's CommandText property to the name of
the stored proc, and it's CommandType property to StoredProcedure.
2) Create a SqlParameter object for each named parameter, assign it the
actual parameter value, and add the Parameter to the SqlCommand's Parameters
collection.

3) Assign the Command to the SelectCommand property of the DataAdapter and
continue as you did before.

--Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top