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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 ASP.NET and Deleting rows

Author  Topic 

Mtherrien
Starting Member

2 Posts

Posted - 2011-11-03 : 11:08:21
I have an asp.net website that I have created for employees so submit their timesheets online.

The application already exists as a VB.NET Windows Form Application that has a strongly typed dataset, so writing and completing all of these sql commands manually is very different for me, and I'll admit, I'm struggling .

There are rows in a table called Calendar. If there is previously submitted data, the previous data gets deleted and the new data added. I can query and insert rows fine, but it's like the delete command doesn't actually want to commit. If I requery after deleting, using the same sql connection, it returns that there are no rows (they have been deleted), but if I close the connection and then open again and requery, they are still there.

This is my current code for deleting the rows:
     Dim sql As String
Dim sstart As DateTime = GetFirstDOW(Calendar1.SelectedDate)
Dim mycommand As SqlCommand
Dim thisTransaction As SqlTransaction
Using myConnection As New SqlConnection(connString)
sql = "DELETE FROM Calendar WHERE (UserID = N'" & empID & "') AND (StartDate >= CONVERT(DATETIME, '" & sstart.Year & "-" & sstart.Month & "-" & sstart.Day & " 00:00:00', 102)) AND (StartDate <= CONVERT(DATETIME, '" & sstart.AddDays(6).Year & "-" & sstart.AddDays(6).Month & "-" & sstart.AddDays(6).Day & " 00:00:00', 102))"
mycommand = New SqlCommand(sql, myConnection)
mycommand.Connection.Open()
thisTransaction = myConnection.BeginTransaction()
mycommand.Transaction = thisTransaction
mycommand.ExecuteNonQuery()
thisTransaction.Commit()
mycommand.Connection.Close()

End Using


Any help you can provide here??

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-03 : 14:12:32
do you have some trigger on table for instead of delete action?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Mtherrien
Starting Member

2 Posts

Posted - 2011-11-03 : 14:55:08
No triggers on the table at all, and the same sql statement works if run through SQL Management Studio Express.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-04 : 04:31:42
is there any exception you're getting trying to run it from app? what credential its using while running from the app?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jassi.singh
Posting Yak Master

122 Posts

Posted - 2011-11-04 : 08:40:44
Work around is that you can write stored procedure and can implement transaction over there.
http://www.codeproject.com/KB/database/sqlservertransactions.aspx

Please mark answer as accepted if it helped you.

Thanks,
Jassi Singh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-04 : 12:46:12
quote:
Originally posted by jassi.singh

Work around is that you can write stored procedure and can implement transaction over there.
http://www.codeproject.com/KB/database/sqlservertransactions.aspx

Please mark answer as accepted if it helped you.

Thanks,
Jassi Singh


so what difference does it make in above scenario?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -