我想在 c# 中使用存储过程。我在 sql server 中创建存储过程,并在程序中调用它。但是当我使用断点功能时,我知道数据不是从数据库中检索到的,因为断点跳过了循环。
.aspx 代码:
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="store" />
<asp:Label ID="Label9" runat="server" Text="Label"></asp:Label>
c#代码:
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);
}
}
存储过程:
CREATE PROCEDURE procedure3
AS
BEGIN
select menuename from menue;
END
GO