SQL Stored Procedure fired from C# Code-Behind not working on UPDATE
Posted
by
CSSHell
on Stack Overflow
See other posts from Stack Overflow
or by CSSHell
Published on 2011-06-26T01:29:22Z
Indexed on
2011/06/26
8:22 UTC
Read the original article
Hit count: 176
I have a stored procedure called from a C# code-behind. The code fires but the update command does not get performed. The stored procedure, if run directly, works. I think I am having a brain fart. Please help. :)
CODEBEHIND
protected void btnAbout_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection(strConnection);
SqlCommand myCommand = new SqlCommand("spUpdateCMSAbout", myConnection);
myConnection.Open();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@AboutText", SqlDbType.NVarChar, -1).Value = txtAbout.Text.ToString();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
STORED PROCEDURE
ALTER PROCEDURE fstage.spUpdateCMSAbout
(
@AboutText nvarchar(max)
)
AS
BEGIN
SET NOCOUNT ON;
UPDATE fstage.staticCMS SET About = @AboutText;
END
HTML
<asp:Button ID="btnAbout" runat="server"
Text="Save" CausesValidation="False" onclick="btnAbout_Click"
UseSubmitBehavior="False" />
C# .NET 4.0
© Stack Overflow or respective owner