Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString);
     con.Open();
     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();
         reader.Close();
    con.Close();
}
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
Edited 15-Jan-13 20:43pm
v4
Rate this: bad
good
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);
Conn.Open();
reader= command.ExecuteReader();
while(reader.Read())
{
        //do it whatever you want
}
  Permalink  
Comments
Abhinav S at 16-Jan-13 3:31am
   
5!
Prasad_Kulkarni at 17-Jan-13 8:38am
   
Thank you :D
Rate this: bad
good
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 -
http://forums.codeguru.com/showthread.php?373179-How-to-call-Stored-Procedure-in-ASP.NET[^]
http://www.c-sharpcorner.com/UploadFile/gtomar/storedprocedure12052007003126AM/storedprocedure.aspx[^]
http://support.microsoft.com/kb/306574[^]
  Permalink  
Comments
Prasad_Kulkarni at 16-Jan-13 2:31am
   
+5! :D
Abhinav S at 16-Jan-13 3:30am
   
Thanks.

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

  Print Answers RSS
0 OriginalGriff 365
1 Nirav Prabtani 268
2 Richard Deeming 215
3 CHill60 170
4 _Amy 145
0 OriginalGriff 8,104
1 Sergey Alexandrovich Kryukov 7,045
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
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