Maybe one of you can help me..
How do I clone the structure of a table into a dataset without populating the dataset.. Basically I want to take a dataset and make it have all the fields of a specific table without having to Fill it.
Printable View
Maybe one of you can help me..
How do I clone the structure of a table into a dataset without populating the dataset.. Basically I want to take a dataset and make it have all the fields of a specific table without having to Fill it.
Anybody?
One way is to populate the dataset then use the method .WriteXMLSchema or something like this . It outputs an XML file that contains the structure only . You can use ReadXMLSchema to skin in the new dataset . Apparently you don't want to do this though ....:DQuote:
Originally posted by Hinder
Anybody?
Ah ok, so I only have to do this once then I can just load it from the schema right? Hmm so this only needs to be done everytime the original database table structure has been modified.. Ill try it, thanks Pirate..Quote:
Originally posted by Pirate
One way is to populate the dataset then use the method .WriteXMLSchema or something like this . It outputs an XML file that contains the structure only . You can use ReadXMLSchema to skin in the new dataset . Apparently you don't want to do this though ....:D
Yes . That's all theoritically speaking :)Quote:
Originally posted by Hinder
Ah ok, so I only have to do this once then I can just load it from the schema right? Hmm so this only needs to be done everytime the original database table structure has been modified.. Ill try it, thanks Pirate..
Ok what am I missing here.. It doesn't error out but it's not adding the new data to the database..
Code:Public Function SaveAccount(ByVal inAcct As IO_Client) As Boolean
Dim oConn As New SqlConnection(oCS)
Dim strSQL As String = "SELECT * FROM Accounts"
Dim oAdapter As New SqlDataAdapter(strSQL, oConn)
Dim ds As New DataSet
Try
'Import the table design
ds.ReadXmlSchema(Application.StartupPath & "\schemas\accounts.xml")
'Let's make a new row
Dim dr As DataRow = ds.Tables("Accounts").NewRow
'Add the values to the row
dr("AcctName") = inAcct.Account.AcctName
dr("AcctPass") = inAcct.Account.AcctPass
dr("AcctMail") = inAcct.Account.AcctMail
dr("AcctBanned") = CType(inAcct.Account.AcctBanned, Byte)
dr("AcctCreated") = inAcct.Account.AcctCreated
dr("AcctPurge") = inAcct.Account.AcctPurge
dr("AcctLastIP") = inAcct.Account.AcctLastIP
'Update the database
oAdapter.Update(ds, "Accounts")
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
'Close the connection
oConn.Close()
End Try
End Function
Don't I need to have some kind of command builder here to have this work?
Yes . It generates all the commands for updating , deleting, insert .