Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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
Updated 15-Jan-13 20:43pm
v4

Something like this:

C#
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
}
 
Share this answer
 
Comments
Abhinav S 16-Jan-13 3:31am    
5!
Prasad_Kulkarni 17-Jan-13 8:38am    
Thank you :D
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[^]
 
Share this answer
 
Comments
Prasad_Kulkarni 16-Jan-13 2:31am    
+5! :D
Abhinav S 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900