?
Solved

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

Posted on 2010-11-27
4
Medium Priority
?
639 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 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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