Note that there are some explanatory texts on larger screens.

plurals
  1. PONew at using Visual Studio, how to add tables to a DB?
    text
    copied!<p>I have a school assignment where we are to fill in some SQL-statements in a code we got from our teacher. We are also to make tree different tables into a db which already exists. When I try to make a new class for adding these tables I think Im doing something wrong. The tables re never created. Why?!</p> <p>DB CONNECTION: </p> <pre><code>Public Class ClassConnection 'Mot citrix Dim Koppling As New System.Data.SqlClient.SqlConnection("Initial Catalog=EmbeddedVB; Data Source=LUiis02; Integrated Security=true") 'Mot access 'Dim Koppling As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data source=Poster.mdb") 'lokalt mot SQL-server 'Dim Koppling As New System.Data.SqlClient.SqlConnection("Initial Catalog=Testar;Data Source=(local); Integrated Security=true;") Public ReadOnly Property ReturneraKoppling() As SqlClient.SqlConnection Get Return Koppling End Get End Property Sub open() Koppling.Open() End Sub Sub close() Koppling.Close() End Sub End Class </code></pre> <p>TABLES (for creating)</p> <pre><code>Public Class Tables Private mySqlConnection As New ClassConnection Private myAdapter As SqlDataAdapter Private mySqlCommand As New SqlCommand Private ds As DataSet Private gammaltPnr As String Public Sub fyllDB() mySqlCommand.Connection = mySqlConnection.ReturneraKoppling() mySqlCommand.CommandType = CommandType.Text mySqlConnection.open() mySqlCommand.CommandText = "CREATE TABLE IF NOT EXIST Kurs4918(" &amp; "kursnamn char(30) NOT NULL PRIMARY KEY " &amp; ")" myAdapter = New SqlDataAdapter(mySqlCommand) mySqlCommand.ExecuteNonQuery() mySqlConnection.close() mySqlConnection.open() mySqlCommand.CommandText = "CREATE TABLE IF NOT EXIST Elev4918 (" &amp; "pnr char(11) NOT NULL PRIMARY KEY, " &amp; "fornamn char(20), " &amp; "efternamn char(20), " &amp; "ort char(15) " &amp; ") " myAdapter = New SqlDataAdapter(mySqlCommand) mySqlCommand.ExecuteNonQuery() mySqlConnection.close() mySqlConnection.open() mySqlCommand.CommandText = "CREATE TABLE IF NOT EXIST KursElev4918(" &amp; "pnr char(11) NOT NULL PRIMARY KEY, " &amp; "kursnamn char(30) " &amp; ") " myAdapter = New SqlDataAdapter(mySqlCommand) mySqlCommand.ExecuteNonQuery() mySqlConnection.close() End Sub </code></pre> <p>The startup Form1.vb (this should run fyllDB() from Tables right?....</p> <pre><code>Public Class frmMain Inherits System.Windows.Forms.Form Private db As New Tables Private Sub fill() db.fyllDB() End Sub </code></pre>
 

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