Results 1 to 5 of 5

Thread: deleting a row from a mssql database

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    deleting a row from a mssql database

    how do i do this in asp.net? i am quite new to SQL programming so i dont really know how to do it...in C# i've tried this just for testing purposes..:
    Code:
    SqlConnection connection = new SqlConnection(CONNECTION_STRING);
    connection.Open();
    SqlCommand command = connection.CreateCommand();
    command.CommandText = "DELETE * FROM DailyDev";
    int res = command.ExecuteNonQuery();
    connection.Close();
    but i am gettin a "System Error"

    what am i doing wrong? also how is the fastest way to access the database and delete the records..i am doing in a way its too slower?

    feedback appreciated!
    \m/\m/

  2. #2
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    this way seems to be fast and efficent...



    VB Code:
    1. Dim strConnection As String = "Provider=MSDAORA;Password=" & password & ";User ID=" & userid & ";Data Source=" & database
    2.         Dim strSQL As String = "delete from pbss.pbss_bid_schedule where bid_id ='" & ID & "'"
    3.         Dim objConnection As New OleDbConnection(strConnection)
    4.        Try
    5.             Dim objCommand As New OleDbCommand(strSQL, objConnection)
    6.             objConnection.Open()
    7.             objCommand.ExecuteNonQuery()
    8.         Catch ex As Exception
    9.             lblMsg.Text = ("Delete Error " & Err.Description)
    10.             objConnection.Close()
    11.             Finally
    12. objConnection.Close()
    13.         End Try
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    "delete * .....

    should just be

    "delete .....

    the best way to delete all data is to drop the table, and then re-create it using a stored procedure that you will have already created (u can use stored procedures to create tables).
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  4. #4
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    Originally posted by nswan
    "delete * .....

    should just be

    "delete .....

    the best way to delete all data is to drop the table, and then re-create it using a stored procedure that you will have already created (u can use stored procedures to create tables).
    No offence but that's not such a good approach in a multi-user environment among other reasons.

    Other users may get errors when the table is dropped.
    I doubt the drop transaction could be rolled back if necessary.
    Also there's considerable overhead wifh freeing up the table resources and then recreating them.

    IMO much better to stick with the DELETE cmd...

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    no i agree it's not the best way to do it but if you want to delete all data from a large table with lots of records it's the quickest.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width