Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your CREATE TABLE and DROP TABLE statements are not quite right. If you have SQL Server Management Studio, you can use it to see how to make those statements: right-click an existing table in the Object Explorer pane and choosing "Script Table as..."->"DROP and CREATE to"->"New Query Editor Window". You will get something similar to</p> <pre><code>USE [testing] GO /****** Object: Table [dbo].[testTable] Script Date: 11/21/2012 20:35:02 ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[testTable]') AND type in (N'U')) DROP TABLE [dbo].[testTable] GO USE [testing] GO /****** Object: Table [dbo].[testTable] Script Date: 11/21/2012 20:35:02 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[testTable]( [number] [int] NULL, [str] [nchar](10) NULL, [tim] [time](7) NULL ) ON [PRIMARY] GO </code></pre> <p>From which you should be able to pick out the parts you need.</p> <p>To execute the DROP/CREATE statements, use the <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx" rel="nofollow">SqlCommand.ExecuteNonQuery Method</a>.</p> <p>EDIT:</p> <p>Thus, your FyllDb method would be more like this:</p> <pre><code>Public Sub FyllDb() Dim sqlCmd As New SqlCommand Dim sqlConn = New SqlConnection("Server=.\SQLEXPRESS;Database=testing;Trusted_Connection=True;") sqlCmd.Connection = sqlConn sqlCmd.CommandText = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[testTable2]') AND type in (N'U')) DROP TABLE [dbo].[testTable2]" Try sqlConn.Open() sqlCmd.ExecuteNonQuery() Catch ex As Exception MsgBox("Error deleting table: " &amp; ex.Message) Finally sqlConn.Close() End Try sqlCmd.CommandText = "CREATE TABLE [dbo].[testTable2]( [number] [int] NULL, [str] [nchar](10) NULL, [tim] [time](7) NULL) ON [PRIMARY]" Try sqlConn.Open() sqlCmd.ExecuteNonQuery() Catch ex As ArgumentException MsgBox("Error creating table: " &amp; ex.Message) Finally sqlConn.Close() End Try End Sub </code></pre> <p>-- tested as working with VS2012/SQL Server 2008 R2 Express/Windows 7 x64.</p> <p>Please adjust to your table definition.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload