I want to use a stored procedure in c#. I create the stored procedure in sql server and I call it in the program. But when I use the breakpoint feature, I come to know that the data is not retrieved from the db as the breakpoint skips over the loop..
.aspx code:
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="store" />
<asp:Label ID="Label9" runat="server" Text="Label"></asp:Label>
c# code:
public void store(object sender, EventArgs ser)
{
try
{
// c reate and open a connection object
SqlConnection conn = Class3.GetConnection();
// 1. create a command object identifying the stored procedure
SqlCommand cmd = new SqlCommand("storeprocedure3", conn);
// 2. set the command object so it knows to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
// 3. add parameter to command, which will be execute the command
SqlDataReader rdr = cmd.ExecuteReader();
// iterate through results, printing each to console
while (rdr.Read())
{
Label9.Text = rdr["menuename"].ToString();
}
}
catch (Exception sa)
{
Console.WriteLine(sa);
}
}
stored procedure:
CREATE PROCEDURE procedure3
AS
BEGIN
select menuename from menue;
END
GO
Console.WriteLineis not very useful in a web application) - is the connection executing as the right user? (from menueis ambiguous - it depends on the user) - when is this running? also; needs a lot moreusing...