Adding tableadapters to table  
Author Message
Music Mogul

PostPosted: Visual Basic Express Edition, Adding tableadapters to table Top

I made a program that creates tables during runtime. These tables are added to the dataset i made with the help of the datasource wizard. At the end of my code i used the WriteXMLSchema to save the dataset to my *.xsd file. Now in design view, i open this save *.xsd file. I'm getting errors that tableadapters that was pervious made with the wizard, are no longer defined. In my sourcecode, I can only use the tableadapters that was previously made with the wizard. but i can't link it to the table that i just created in the database. Can someone tell me how to make tableadapters during runtime ( also the fill method).

Visual Studio Express Editions33  
Bhanu Prakash Nunna - MSFT

PostPosted: Visual Basic Express Edition, Adding tableadapters to table Top


Please go through the below link. Hope this helps.

Thank you,

Music Mogul

PostPosted: Visual Basic Express Edition, Adding tableadapters to table Top

I can make tableadapters for tables in the design view. That is no problem. Say for example. During runtime, the user decides he wants to add another table in the database. The user clicks on the button to create a table. Behind that button has code to make a connection to the database. After connection is made the table is created. This table is added to the dataset. Then the columns are created by using the datatable object. But now... this table that just been created doesn't have any tableadapters. Without the tableadapters, I can't execute the method fill, getdata. This is what i got so far.

Connect to database
execute sqlstring
'Open database

'Execute Command

Catch ex As Exception

MsgBox(ex.ToString, MsgBoxStyle.Question)

End Try
Filename = "CreateTableDataset.xsd"
Dim AddTable As DataTable =CreateTable.Tables.Add(tablenaam)
Dim Customer_Id As DataColumn = AddTable.Columns.Add( _
"Customer_Id", Type.GetType("System.Int32"))
AddTable .Columns.Add("Firstname", Type.GetType("System.String"))
AddTable .Columns.Add("Lastname", Type.GetType("System.String"))
AddTable .Columns.Add("Telephone", Type.GetType("System.String"))
AddTable .Columns.Add("Mobile_number", Type.GetType("System.String"))

AddTable .PrimaryKey = New DataColumn() {Customer_Id}
I tried defining a new tableadapter by doing the following.

Dim newtableadapter as new CreateTabletableadapters.Table1tableadapter

But i don't want to use the tableadapter from table1 i want to create a tableadapter for the table that just been created. And from there i would like to add method, fill and getdata(). I would like to do this during RUNTIME NOT IN Design view.

At the end of my code i wrote the following.


When i open this file in my design view, I get an error message, saying that tableadapters for all tables are not defined. Even the tableadapters that i created with the wizard are no longer defined. On yea one last note. I used the wizard to create the first table and tableadapter. I hope this gives an idea on what i’m trying to accomplish.


PostPosted: Visual Basic Express Edition, Adding tableadapters to table Top

I never mess with table adapters or the wizard - I usually use dataadapters:

Public Function PersistTable(ByVal Table As DataTable, Optional ByVal NewRow As DataRow = Nothing) As Boolean

' adodb.PersistTable - called by any routine needing to make permanent changes in a table.

' Usually this would be midlevel procedures in IOSUBS

' PersistTable has an optional argument for appending a new row on a table.

Adapter.SelectCommand = New OleDbCommand("Select * from [" & Table.TableName & "]", con)

Dim builder As New OleDbCommandBuilder(Adapter)

builder.QuotePrefix = "["

builder.QuoteSuffix = "]"

If NewRow IsNot Nothing Then

NewRow.Item(DataRecords.ciRecordNo) = Table.Rows.Count


End If



Catch e As Exception

'Throw e

MsgBox("Error persisting Table: " + Table.TableName + vbCrLf + "Exception was: " + e.Message, _

MsgBoxStyle.Information, "ADONET.PersistTable")

End Try

End Function

Public Function GetTable(ByVal tableName As String, Optional ByVal OrderRows As Boolean = True) As DataTable

' ADONET.GetTable - Called by: "Everywhere".

' Function: Given a Table name string; fill and return a datatable from an adapter

GetTable = Nothing

If con.ConnectionString = "" Then Exit Function

Dim OrderString As String = " order by RecordNo"

If Not OrderRows Then OrderString = ""

Adapter = New OleDbDataAdapter("Select * from [" & tableName & "]" & OrderString, con)

Dim result As New DataTable(tableName)



Return result

Catch e As Exception

'If System.Diagnostics.De****.IsAttached() Then Throw e ' This is to invite making this visible on the call stack

MsgBox("Error selecting Table: " + tableName + vbCrLf + "Exception was: " + e.Message _

& vbCrLf & "The connection string is: " & vbCrLf & con.ConnectionString, _

MsgBoxStyle.Information, "ADONET.GetTable")


'Return Nothing

End Try

'End Using

End Function

End Class