我正在尝试使用存储过程插入表中。执行的存储产品结果为零(0)。我猜这意味着存储过程是成功的。
但是当我查看表格时,记录没有添加。我该如何解决?
SQL
ALTER PROCEDURE displayToDO
@ID int =2,
@Title varchar(50),
@Description varchar(255),
@Date date,
@Time time,
@Location varchar(50),
@Priority varchar(20),
@NotificationType varchar(30)
AS
BEGIN
INSERT INTO toDOLIST(ID, Title, Description, Date, Time, Location, Priority, NotificationTYPE)
VALUES (@Title, @Description, @Date, @Time, @Location, @Priority, @NotificationType)
END
Asp.net:
<form id="form1" runat="server">
<div>
<div class="insertData">
<asp:Label ID="title" runat="server" Text="Title"></asp:Label>
<asp:TextBox ID="titleBox" runat="server"></asp:TextBox><br />
<asp:Label ID="description" runat="server" Text="Description"></asp:Label>
<asp:TextBox ID="descriptionBox" runat="server"></asp:TextBox><br />
<asp:Label ID="dateLabel" runat="server" Text="Date"></asp:Label>
<asp:Calendar ID="date" runat="server"></asp:Calendar><br />
<asp:Label ID="time" runat="server" Text="Time"></asp:Label>
<asp:TextBox ID="timeBoxHr" runat="server"></asp:TextBox> <asp:TextBox ID="timeBoxMin" runat="server"></asp:TextBox>
<br />
<asp:Label ID="location" runat="server" Text="Location"></asp:Label>
<asp:TextBox ID="locationBox" runat="server"></asp:TextBox><br />
<asp:Label ID="priority" runat="server" Text="Priority"></asp:Label>
<asp:DropDownList ID="priorityDrop" runat="server">
<asp:ListItem>-</asp:ListItem>
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="notification" runat="server" Text="Notification Type"></asp:Label>
<asp:DropDownList ID="notificationDrop" runat="server">
<asp:ListItem>12 hrs before</asp:ListItem>
<asp:ListItem>1 day Before</asp:ListItem>
<asp:ListItem>3 Day before</asp:ListItem>
<asp:ListItem>A Week before</asp:ListItem>
</asp:DropDownList>
</div>
<br />
<asp:Button ID="Button2" runat="server" Text="Insert" onclick="Button2_Click" />
<br /><br /><br /><br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Display" />
<br /><br /><br /><br />
<asp:GridView ID="GridView1" runat="server"
onselectedindexchanged="GridView1_SelectedIndexChanged">
</asp:GridView>
</div>
</form>
C#:
protected void Button2_Click(object sender, EventArgs e)
{
String time = timeBoxHr.Text + ":" + timeBoxMin.Text + ":00";
using (SqlConnection conn = new SqlConnection(ConfigurationString))
{
SqlCommand scommand = new SqlCommand(sql, conn);
scommand.CommandType = CommandType.StoredProcedure;
scommand.Parameters.Add("@ID", SqlDbType.Int).Value = titleBox.Text;
scommand.Parameters.Add("@Title", SqlDbType.VarChar, 50).Value = titleBox.Text;
scommand.Parameters.Add("@Description", SqlDbType.VarChar, 255).Value = descriptionBox.Text;
scommand.Parameters.Add("@Date", SqlDbType.Date).Value = date.SelectedDate.ToShortDateString();
scommand.Parameters.Add("@Time", SqlDbType.Time).Value = time;
scommand.Parameters.Add("@Location", SqlDbType.VarChar, 50).Value = locationBox.Text;
scommand.Parameters.Add("@Priority", SqlDbType.VarChar, 20).Value = priorityDrop.Text;
scommand.Parameters.Add("@NotificationType", SqlDbType.VarChar, 30).Value = notificationDrop.Text;
try
{
if (scommand.Connection.State == ConnectionState.Closed)
{
scommand.Connection.Open();
}
scommand.ExecuteNonQuery();
}
catch (Exception)
{
}
finally
{
scommand.Connection.Close();
}
}