Problem deleting row from following table ...

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<pre class="prettyprint lang-sql" style="
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[file_upload](
[file_id] [uniqueidentifier] NOT NULL,
[user_id] [uniqueidentifier] NOT NULL,
[file_name] [nvarchar](256) NOT NULL,
[file_phy_path] [nvarchar](max) NOT NULL,
[file_otp] [varchar](10) NOT NULL,
[file_uploadtime] [datetime] NOT NULL,
[file_exptime] [datetime] NOT NULL,
CONSTRAINT [PK_file_upload] PRIMARY KEY CLUSTERED
(
[file_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[file_upload] WITH CHECK ADD CONSTRAINT [FK_file_upload_aspnet_Users] FOREIGN KEY([user_id])
REFERENCES [dbo].[aspnet_Users] ([UserId])
GO

ALTER TABLE [dbo].[file_upload] CHECK CONSTRAINT [FK_file_upload_aspnet_Users]
GO[/code]
when i try to delete using code as below
<pre class="prettyprint" style=" protected void Cancelbtn_Click(object sender, EventArgs e)
{
File.Delete(path);


using (SqlConnection con = new SqlConnection(strcon))
{
string delcmd = "delete from file_upload where file_id=@fileid";
Response.Write(fileid);
SqlCommand cmd = new SqlCommand(delcmd, con);
cmd.Parameters.AddWithValue("@file_id", fileid);


try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch { }
finally
{
con.Close();
}

}

}[/code]
when i click ...i can delete file from the folder....but can not delete that row entry from database....but when i run delete statement in sql management studio...i can delete row....I think there must be problem with ADO.NET C# code....so place this
in C# forum...<br/>

View the full article
 
Back
Top