truncate table in sql 2005 by vb,net code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • atk8877
    New Member
    • May 2009
    • 10

    truncate table in sql 2005 by vb,net code

    hi everyone .. well i am truing 2 make a button when i click it would truncate the data in table , i am trying 2 do this by vb.net 2005.\
    so if anyone got the code or an example 4 it would b nice .
    thanx 4 all.
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Code:
    System.Data.SqlClient.SQLConnection con=new System.Data.SqlClient.SQLConnection("server=local;database=EmpDB;user id=sa;password=sa");
    
    System.Data.SqlClient.SQLCommand cmd=new System.Data.SqlClient.SQLCommand();
    
    cmd.Connection=con;
    cmd.CommandText="Delete from TableName";
    
    con.Open();
    cmd.ExecuteNonQuery();
    con.Close();
    Last edited by PRR; Jun 3 '09, 10:07 AM. Reason: Code in [code] tags...

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Or instead of using the SQL "DELETE" command you could use the "TRUNCATE" command.

      Comment

      • atk8877
        New Member
        • May 2009
        • 10

        #4
        ok guys , thanx 4 help , but i am using sql 2005 and it hasnt a trusted connection so i dont have user id or password
        so it gives me this error :
        Login failed for user ''. The user is not associated with a trusted SQL Server connection.
        so what s the big idea.

        Comment

        • atk8877
          New Member
          • May 2009
          • 10

          #5
          ok thanks guys but iut seems that it call a trusted connection and i dont use it , so i dont have user name or password, so what

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            What type of authentication is the SQL server using?
            Does it use Windows Authentication, SQL Authentication or both?

            Comment

            Working...