Pages

Monday, June 2, 2014

How to Create a Table in VB.NET Through Coding at a Specific Location

You use the VB.NET connection element to specify a location on your network from which you query data. After you set up the connection element, you use a SQL query to create a new table. Programmers use the "create table" SQL statement to dynamically create SQL tables on a database server.

Instructions

    1

    Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET Framework," and then click the Visual Studio shortcut to load the compiler. Open the VB.NET project after VS opens.

    2

    Create the specific connection location for the query to run. The connection VB.NET string lets you specify the database and database server name on which the queries run. The following code shows you how to create the connection:

    Dim myconnect As New SqlConnection("Data Source=servername;Initial Catalog=DatabaseName;Persist Security Info=True;")

    Replace "servername" with the server that contains your data. Replace "DatabaseName" with the database name.

    3

    Implement the connection with the SQL query that creates the table. The following code sets up the "create table" command:

    Dim sqlquery As New SqlCommand("create table mytable", myconnect)

    The code above creates a table named "mytable" on the server.

    4

    Execute the SQL query on the server you defined in the connection string. The following code creates the table on your server:

    sqlquery.ExecuteNonQuery()

0 comments:

Post a Comment