Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. create table command from listview

create table command from listview

Scheduled Pinned Locked Moved Visual Basic
databasecsharpsqlitehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    newbjohny
    wrote on last edited by
    #1

    Hi, I am creating a front-end to the sqlite DBMS using VB.Net 2002. I have managed to get the name of the table, field names and types from user input displayed into a listview but I can only get the Create table command to accept the last input values, so if the table has more than one field(which nealry every table has) it simply ignores the previously entered fields. How would I get it to create an SQL query with all the inputted field details? I have inserted the code I have used so far. Many thanks for your help. This button opens up a new form for the user to input the field name and select the field type then brings them back and displays them in a listview. Public Sub btnAddColumn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddColumn.Click Dim frmAddColumns1 As New frmAddColumns() frmAddColumns1.ShowDialog(Me) fldName = frmAddColumns.ColumnNameTB.Text fldAttribute = frmAddColumns.ColumnTypeTB.SelectedItem 'Create ListViewItem Dim item1 As New ListViewItem(fldName, 0) item1.SubItems.Add(fldAttribute) 'Add the items to the ListView. listView1.Items.AddRange(New ListViewItem() {item1}) Me.Controls.Add(listView1) End Sub This button takes the input table name, field name and attributes and creates the SQL command to send to the database to create the table: Private Sub btnCreateTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTable.Click Dim tblName As String tblName = txtTableName.Text.ToString() If Len(txtTableName.Text) < 1 Then MessageBox.Show("Please type a name for the table") ElseIf Len(txtTableName.Text) > 0 Then Try dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;") dbConn.createSQLCommand() dbConn.createTable("CREATE TABLE " & tblName & "(" & fldName & " " & fldAttribute & ")") MessageBox.Show("Table created successfully") Me.Close() Dim frmInsertData1 As frmInsertData = New frmInsertData() frmInsertData1.Show() Catch es As Exception MessageBox.Show(es.Message) End Try End If End Sub

    F 1 Reply Last reply
    0
    • N newbjohny

      Hi, I am creating a front-end to the sqlite DBMS using VB.Net 2002. I have managed to get the name of the table, field names and types from user input displayed into a listview but I can only get the Create table command to accept the last input values, so if the table has more than one field(which nealry every table has) it simply ignores the previously entered fields. How would I get it to create an SQL query with all the inputted field details? I have inserted the code I have used so far. Many thanks for your help. This button opens up a new form for the user to input the field name and select the field type then brings them back and displays them in a listview. Public Sub btnAddColumn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddColumn.Click Dim frmAddColumns1 As New frmAddColumns() frmAddColumns1.ShowDialog(Me) fldName = frmAddColumns.ColumnNameTB.Text fldAttribute = frmAddColumns.ColumnTypeTB.SelectedItem 'Create ListViewItem Dim item1 As New ListViewItem(fldName, 0) item1.SubItems.Add(fldAttribute) 'Add the items to the ListView. listView1.Items.AddRange(New ListViewItem() {item1}) Me.Controls.Add(listView1) End Sub This button takes the input table name, field name and attributes and creates the SQL command to send to the database to create the table: Private Sub btnCreateTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTable.Click Dim tblName As String tblName = txtTableName.Text.ToString() If Len(txtTableName.Text) < 1 Then MessageBox.Show("Please type a name for the table") ElseIf Len(txtTableName.Text) > 0 Then Try dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;") dbConn.createSQLCommand() dbConn.createTable("CREATE TABLE " & tblName & "(" & fldName & " " & fldAttribute & ")") MessageBox.Show("Table created successfully") Me.Close() Dim frmInsertData1 As frmInsertData = New frmInsertData() frmInsertData1.Show() Catch es As Exception MessageBox.Show(es.Message) End Try End If End Sub

      F Offline
      F Offline
      fredde_d
      wrote on last edited by
      #2

      In btnAddColumn_Click() you assign fldName and fldAttribute and add them to the ListView but in btnCreateTable_Click() you don't iterate the ListView to retrieve all added columnnames and datatypes. You only use the las assigen values for fldName and fldAttribute. BR Fredrik -- modified at 10:05 Wednesday 12th July, 2006

      N 1 Reply Last reply
      0
      • F fredde_d

        In btnAddColumn_Click() you assign fldName and fldAttribute and add them to the ListView but in btnCreateTable_Click() you don't iterate the ListView to retrieve all added columnnames and datatypes. You only use the las assigen values for fldName and fldAttribute. BR Fredrik -- modified at 10:05 Wednesday 12th July, 2006

        N Offline
        N Offline
        newbjohny
        wrote on last edited by
        #3

        Hi Fredrik, thanks for your help, I've managed to get all rows from the listview using a for loop and adding them to a string. thanks again for your help john

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups