Results 1 to 2 of 2

Thread: create table command from listview

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    14

    create table command from listview

    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.

    VB Code:
    1. Public Sub btnAddColumn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddColumn.Click
    2. Dim frmAddColumns1 As New frmAddColumns()
    3. frmAddColumns1.ShowDialog(Me)
    4. fldName = frmAddColumns.ColumnNameTB.Text
    5. fldAttribute = frmAddColumns.ColumnTypeTB.SelectedItem
    6. 'Create ListViewItem
    7. Dim item1 As New ListViewItem(fldName, 0)
    8. item1.SubItems.Add(fldAttribute)
    9. 'Add the items to the ListView.
    10. listView1.Items.AddRange(New ListViewItem() {item1})
    11. Me.Controls.Add(listView1)
    12. 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:


    VB Code:
    1. Private Sub btnCreateTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTable.Click
    2. Dim tblName As String
    3. tblName = txtTableName.Text.ToString()
    4. If Len(txtTableName.Text) < 1 Then
    5. MessageBox.Show("Please type a name for the table")
    6. ElseIf Len(txtTableName.Text) > 0 Then
    7. Try
    8. dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;")
    9. dbConn.createSQLCommand()
    10. dbConn.createTable("CREATE TABLE " & tblName & "(" & fldName & " " & fldAttribute & ")")
    11. MessageBox.Show("Table created successfully")
    12. Me.Close()
    13. Dim frmInsertData1 As frmInsertData = New frmInsertData()
    14. frmInsertData1.Show()
    15. Catch es As Exception
    16. MessageBox.Show(es.Message)
    17. End Try
    18. End If
    19. End Sub
    Last edited by si_the_geek; Jul 11th, 2006 at 06:52 AM. Reason: added vbcode tags for readability

  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    14

    Re: create table command from listview

    well thanks everyone who kindly ignored my plea, I'll know where to come next time for help....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width