I need a super simple way to insert a datarow into sql using vb.net, the datarow has same scheme.

I need a super simple way to insert a datarow into sql using vb.net, the datarow has same scheme.

It seems simple but my searches have turned up methods that require me to parameter everything.  Isn't there a simple function that someone's already written to insert a datarow?  Maybe I need to change the process which I am reading the data as well.

Thanks for your help,
--john
LVL 3
jdraggiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Malik1947Commented:
check these videos. they give very easy ways to achieve what you're wanting to do.
http://msdn2.microsoft.com/en-us/vbasic/bb466226.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jdraggiAuthor Commented:
That's pretty cool stuff.  I noticed that everything that they are doing revolves around a dataset or datatable.  Which is fine however a lot of my data involves comboboxes and textboxes.  How would you suggest by this method that I interface a textbox or combobox?

Lets say the project needs to call a SQL database, take column1 into textbox1 and column2 into combobox2.  Then after I make changes to either of these I need to click a button to push the changes back to SQL.

My issue here is specifically how do I link the textbox or combobox to that datarow item?


Thanks,
John
0
Malik1947Commented:
one of the tutorials... i think it is the third one shows how to use text boxes and combo boxes. they can enter data into the fields and then you click save then it enters the information into the database.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

jdraggiAuthor Commented:
Yes, I've figured out how to do that stuff... I am currently trying to figure out how to have my combo boxes show the options from a codes section of the database and have the selected item be the option that the database currently has.

Any ideas?

--john
0
jdraggiAuthor Commented:
Currently what I ended up doing was adding a database dataset separate from the LINQ dataobject and setting the combobox to pickup the displaymember and value through the dataset choosing the selected value item that the LINQ dataobject has.

What I'm looking for now is clarity that this is the best way to handle this.  Because this method is new to me I am unlcear if this is the correct method or if I should be using the LINQ data object.

It would appear that if I use LINQ that I would be adding more work to my project because I would then have to create separate select statements for each coded box.

Thanks,
John
0
Malik1947Commented:
I think what you are doing is correct. That's how I would have done it.
0
jdraggiAuthor Commented:
I was working with it and kept trying different combinations...  it's kind of freaky...

What I ended up doing was bringing in a clients database into the LINQ server explorer, then brought in the associated tables.  In my database I already setup the relationship so the field mapping didn't have to be re-mapped.

ok, so now I have a LINQ datasource... here's where it gets cool...  In your datasource explorer expand your database and you'll see your relational datasources.  Right click in the data sources explorer (anywhere) and choose Add new datasource...  you can now drill down and add your codes relationship database...

The tricky part is this...  Normally if you had just been using a text box or a datagridview you would just drag and drop from the original client database source...  in this case, if you want to add a combobox that is going to have the relational codes you have to drill into your codes datasource, you'll see the original database source + (s) so client datasource will now be clients.  ok, so now you will see the same tables and you can change the relational one to a combobox and drag it over to your form.

Now, the second part of this is that you have to click the properties ">" on the combobox and set the data source to your codes data, this gives you the options needed to set the display member and the value member... then you also need to set the selected value member to your original client datasource and it's corresponding field.

Once you do it a couple times it makes sense ...  After I posted I got thinking about what I said because although that method works one of the other videos from your link talked about conversions from datasets and LINQ will still work with your existing application...  so although it does work the preference is to move away from that older method.

The code behind is really sweet too...

Define the database
Dim ClientDB As New MYdbDataContext()

in the load section load up your data:

'Use this to review the sql statements that are actually being sent
ClientDB.Log = Console.Out

'Load up your client
Dim ThisClient = From Client In ClientDB.Clients Where Client.ClientGUID = GlobalClientGUID Select Client
'Assign the client to a datasource that will be update/etc later
ClientBindingSource.DataSource = ThisClient

'Load up your Codes
Dim CD_DOBQuality = From code_dobquality In ClientDB.Code_DOBQualities Select code_dobquality
'Assign the codes to the datasource that the combobox is pulling from
CodeDOBQualityBindingSource.DataSource = CD_DOBQuality

When you're all done and need to save changes...
Me.ClientBindingSource.EndEdit()
ClientDB.SubmitChanges()

So, it's a bit tricky at first but once you get it... it's cake.

The only problem that I'm having now is updating a field via code.  I'm using GUIDs to track everything and can not figure out how to assign the GUID through the software....  IE if I'm not using a textbox/combobox/etc...  This is driving me nuts because it should be the most simple part of this.  LOL

Any ideas?

--John

0
jdraggiAuthor Commented:
OK, figured it out....

Dim NewClient = New Client With {.ClientGUID = GlobalClientGUID}
ClientBindingSource.Add(NewClient)

That was a lot of work to learn about LINQ to SQL but this will save me so much time that it's definitely worth it.

Thanks,
--John
0
jdraggiAuthor Commented:
I wanted to add that we found that the intellisense isn't working in some parts as well...

Dim test As Client = ClientBindingSource.Current
test.FirstName = "John"

is the same as:
ClientBindingSource.Current.FirstName = "John"

However the intellisense doesn't give you the table field names in the latter whereas the Dim'n it out does.

--john
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.