thomas008
Well-known member
Hi
What i am trying to do is check if a table exists by checking if the tablename is in select * from sys.tables. If the table exists i want to show it in a gridview. This part works fine but if the table doesn't exist i want to create the table, place it in my dataset and then update it to the database. When i use my normal procedure of updating a table this doesnt work.
This is the code i use to create the table and update it
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I'm fairly new to using databases so please be kind
	
		
			
		
		
	
				
			What i am trying to do is check if a table exists by checking if the tablename is in select * from sys.tables. If the table exists i want to show it in a gridview. This part works fine but if the table doesn't exist i want to create the table, place it in my dataset and then update it to the database. When i use my normal procedure of updating a table this doesnt work.
This is the code i use to create the table and update it
			
				VB.NET:
			
		
		
		            Dim table As DataTable = New DataTable()
            Dim column As DataColumn
            table.TableName = txtnr.Text
            column = New DataColumn()
            column.DataType = System.Type.GetType("System.Int32")
            column.ColumnName = "ID"
            column.AllowDBNull = False
            column.AutoIncrement = True
            column.AutoIncrementSeed = 1
            column.AutoIncrementStep = 1
            column.Unique = False
            table.Columns.Add(column)
            column = New DataColumn()
            column.DataType = Type.GetType("System.Int32")
            column.ColumnName = "routing"
            column.AllowDBNull = False
            table.Columns.Add(column)
            column = New DataColumn()
            column.DataType = Type.GetType("System.String")
            column.ColumnName = "HHMMSSmin"
            column.AllowDBNull = False
            table.Columns.Add(column)
            column = New DataColumn()
            column.DataType = Type.GetType("System.String")
            column.ColumnName = "HHMMSSmax"
            column.AllowDBNull = False
            table.Columns.Add(column)
            column = New DataColumn()
            column.DataType = Type.GetType("System.Int32")
            column.ColumnName = "goto"
            column.AllowDBNull = False
            table.Columns.Add(column)
            myDataset = New DataSet
            myDataAdapter.Fill(myDataset)
            myDataset.Tables.Add(table)
            If myDataset.HasChanges Then
                myDataAdapter.Update(myDataset, txtnr.Text)
            End If
            Dim view As New DataGridView
            view.DataSource = myDataset.Tables(txtnr.Text)
            view.Visible = True
            view.Width = 600
            Dim punt As New Point(600, 300)
            view.Location = punt
            Controls.Add(view)I'm fairly new to using databases so please be kind

 
	 
 
		 
 
		 
 
		 
 
		