Solved

Convert Command text to stored procedure in asp.net c#

Posted on 2010-11-27
4
635 Views
Last Modified: 2012-05-10
Hello,

I want the following code in asp.net c#  to be changed to use stored procedure with two parameters instead of command text.

 
conReport.Open();
            cmdReport.CommandType = CommandType.Text;
            cmdReport.Connection = conReport;
            cmdReport.CommandText = "Select  * FROM mytable";
            drReport = cmdReport.ExecuteReader();
            dsReport.Tables[0].Load(drReport);
            drReport.Close();
            conReport.Close();

Open in new window


Thanks

Zaki
0
Comment
Question by:zaki100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 13

Accepted Solution

by:
Pryrates earned 250 total points
ID: 34221556
You can switch the CommandType to .StoredProcedure.
Then you can add your parameters.
 "Name" and "Type" must match your parameters of your stored procedure.

you can try something like shown in the code box

Hope that helps
cmdReport.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("Param1", System.Data.SqlDbType.Int);
param.Value = DBNull.Value;
cmdReport.Parameters.Add(param);

param = new SqlParameter("Param2", System.Data.SqlDbType.Int);
param.Value = DBNull.Value;
cmdReport.Parameters.Add(param);

drReport = cmdReport.ExecuteReader();

Open in new window

0
 
LVL 7

Assisted Solution

by:meispisces
meispisces earned 250 total points
ID: 34221787
conReport.Open();
                 cmdReport.Connection = conReport;
           cmdReport= new SqlCommand(StoredProcedureName, connection object)
            cmdReport.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.Add(Parameter-Name1, SqlDbType.Varchar).value= textbox1.text;
            drReport = cmdReport.ExecuteReader();
            dsReport.Tables[0].Load(drReport);
            drReport.Close();
            conReport.Close();

Change is in Bold. For more info refer http://www.c-sharpcorner.com/UploadFile/gtomar/storedprocedure12052007003126AM/storedprocedure.aspx

0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34421770
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question