Using a dataset won't inheritly decrease the amount of trips to the database.
Another approach would be to create a sql string that executes all the commands you want. For example:
dim conn as new sqlconnection(ConfigurationManager.ConnectionStrings("ConnectString").ConnectionString)
dim cmd as new sqlcommand(MyClass.SaveSQL)
conn.open
cmd.executenonquery
conn.close
Assuming MyClass has two string properties col1 and col2, and a collection of tags called TagCollection:
Public Function SaveSQL() as string
dim sql as string
sql="INSERT INTO user_profile(col1,col2) VALUES ('" & col1 & "','" & col2 & "') " -- Note the trailing space in the quotes
for each tag in TagCollection
sql=sql & tag.SaveSQL
next
return sql
end function
And assuming your tag class has a tagname and tagvalue property, then add this function to your tag class:
Public Function SaveSQL() as string
dim sql as string
sql="INSERT INTO TagsTable(TagName,TagValue) VALUES ('" & tagname & "','" & tagvalue & "') " -- Note trailing space in the quotes
-- If there is a child collection, iterate and append their SQL values here
return sql
end function
If the tags table needs the id of the user_profile, then change MyClass SaveSQL like:
Public Function SaveSQL() as string
dim sql as string
sql="DECLARE @MyClassID int INSERT INTO user_profile(col1,col2) VALUES ('" & col1 & "','" & col2 & "') SET @MyClassID=SCOPE_IDENTITY() " -- Note the trailing space in the quotes
for each tag in TagCollection
sql=sql & tag.SaveSQL
next
return sql
end function
Public Function SaveSQL() as string
dim sql as string
sql="INSERT INTO TagsTable(TagName,TagValue,MyClass) VALUES ('" & tagname & "','" & tagvalue & "',@MyClassID) " -- Note trailing space in the quotes
-- If there is a child collection, iterate and append their SQL values here
return sql
end function
Of course, you should make sure all the parameters are properly cleaned before appending them in the SQL String by double single quoting any embedded single quotes, etc.