Click here to Skip to main content
12,886,892 members (37,813 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString);
     SqlCommand cmd = new SqlCommand("Select * FROM Resource", con);
    SqlDataReader reader = cmd.ExecuteReader();
       if (reader.Read())
         FirstName.Text = reader["FirstName"].ToString();
         LastName.Text = reader["LastName"].ToString();
        PrimarySkill.Text = reader["PrimarySkill"].ToString();
       SecondarySkill.Text = reader["SecondarySkill"].ToString();
           Email.Text = reader["Email"].ToString();
       Phone.Text = reader["Phone"].ToString();

by using this code i m able to retrive the data from database into labels using sql server. but how can we do the same for stroed procedure using model. to pass the parameters we use (cmd.parameters.add) how to write the code for geting the data from stored procedure.

i tried to get the data using model with stroed procedure but here i m getting error :

protected void Page_Load(object sender, EventArgs e)
Details obj = new Details();

obj.FN = FN.Text;
obj.LN = LN.Text;
obj.PS = PS.Text;
obj.SS= SS.Text;
obj.E = E.Text;
obj.P = P.Text;
AdoData objado = new AdoData();
lblmessage.Text = objado.userinfo(obj);

Error: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.Label'
Posted 15-Jan-13 19:22pm
Updated 15-Jan-13 20:43pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Something like this:

sqlConnection Conn = new SqlConnection(//your connection string here);
sqlCommand command = new SqlCommand(//your sp name here, Conn);
//Declare a reader
SqlDataReader reader;
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@id", id);
reader= command.ExecuteReader();
        //do it whatever you want
Abhinav S 16-Jan-13 3:31am
Prasad_Kulkarni 17-Jan-13 8:38am
Thank you :D
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Calling stored procedures is fairly similar to the approach you have used here.
Create a stored procedure and assign the results to the label.

Go through these links for help on calling stored procedures in code -[^][^][^]
Prasad_Kulkarni 16-Jan-13 2:31am
+5! :D
Abhinav S 16-Jan-13 3:30am

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100