Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
laurie
Starting Member
2 Posts |
Posted - 2010-10-22 : 22:54:14
|
| HiThis SP fails with syntax error when I call it from the code below however it works when I run it inside SQLExpress2005 interfaceCan anyone point me to the problem. Sorry about the long postAny help would be greatly appreciatedThanksLaurieSP Here++++++++CREATE PROCEDURE [dbo].[deleteRisk] -- Add the parameters for the stored procedure here @Id varChar(36)AS DECLARE @guidID uniqueidentifier SELECT @guidID = CAST(@Id as uniqueidentifier)BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here Delete FROM Risks WHERE Id = @guidIDENDCode Here++++++++++public void DeleteChemical(String Id) { String ErrorTrap; using (SqlConnection mySqlConnection = new SqlConnection(AppConfiguration.ConnectionString)) { SqlCommand myCommand = new SqlCommand("deleteRisk", mySqlConnection); myCommand.Parameters.AddWithValue("@Id", Id); try { mySqlConnection.Open(); myCommand.ExecuteNonQuery(); } catch (Exception EX) { ErrorTrap = EX.Message; } finally { mySqlConnection.Close(); } } }GRIDView Here+++++++++++++++ <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="odsRisk" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" visible="true"/> <asp:BoundField DataField="OriginalName" HeaderText="OriginalName" SortExpression="OriginalName" /> <asp:BoundField DataField="ContentType" HeaderText="ContentType" SortExpression="ContentType" /> <asp:BoundField DataField="DateCreated" HeaderText="DateCreated" SortExpression="DateCreated" /> <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="~/DownloadRisk.aspx?Id={0}" HeaderText="Download" Text="Download" /> <asp:TemplateField HeaderText="View"> <ItemTemplate> <asp:HyperLink ID="lnkView" runat="server" NavigateUrl='<%# Eval("Id", "~/ViewRisk.aspx?Id={0}") %>' Text="View"></asp:HyperLink> </ItemTemplate> </asp:TemplateField> <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" /> </Columns> </asp:GridView> <br /> <asp:ObjectDataSource ID="odsRisk" runat="server" SelectMethod="GetList" DeleteMethod="DeleteChemical" TypeName="RiskInfo" > </asp:ObjectDataSource>Code Behind Here+++++++++++++++protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; String Id = GridView1.Rows[index].Cells[0].Text; odsRisk.DeleteParameters.Add("Id", TypeCode.String, Id.ToString()); odsRisk.Delete(); } |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-23 : 01:39:43
|
| how are you passing the GUID value? also whats the syntax error you got?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
laurie
Starting Member
2 Posts |
Posted - 2010-10-23 : 02:18:55
|
| HiThanks everyome for taking the time to replyI finally found some else in the world who had done the same dumb thing.I forgot the line myCommand.CommandType = CommandType.StoredProcedure;The final code is as followspublic void DeleteChemical(String Id) { String ErrorTrap; Guid myGidID = new Guid(Id); using (SqlConnection mySqlConnection = new SqlConnection(AppConfiguration.ConnectionString)) { SqlCommand myCommand = new SqlCommand("deleteRisk", mySqlConnection); myCommand.CommandType = CommandType.StoredProcedure; // Set up the ID parameter SqlParameter prmId = new SqlParameter("@Id", SqlDbType.UniqueIdentifier); prmId.Value = myGidID; myCommand.Parameters.Add(prmId); try { if (mySqlConnection.State == ConnectionState.Open) { //if the db connection is currently open it, close it. mySqlConnection.Close(); } mySqlConnection.Open(); myCommand.ExecuteNonQuery(); } catch (Exception EX) { ErrorTrap = EX.Message; } finally { mySqlConnection.Close(); } } } |
 |
|
|
|
|
|