Click here to Skip to main content
11,493,154 members (60,850 online)
Rate this: bad
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 20:22pm
Edited 15-Jan-13 21: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 at 16-Jan-13 3:31am
Prasad_Kulkarni at 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 at 16-Jan-13 2:31am
+5! :D
Abhinav S at 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
0 Sergey Alexandrovich Kryukov 419
1 Maciej Los 286
2 F-ES Sitecore 224
3 KarstenK 210
4 CPallini 208
0 Sergey Alexandrovich Kryukov 10,132
1 OriginalGriff 8,630
2 Sascha Lefèvre 3,624
3 Maciej Los 3,392
4 Richard Deeming 2,500

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2015
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