Question How to Insert datagrid data to sql

Summ0ner

New member
Joined
Dec 4, 2009
Messages
2
Programming Experience
1-3
Hi,

I have a datagrid which data i want to insert into sql table. I have tried the following code and it gives me an error:

VB.NET:
        Dim db As New commissionsDataContext
        db.gcstransactions.InsertAllOnSubmit(GridView1.DataSource)
        db.SubmitChanges()

I get the following error:

System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object


What would be the best wat to insert a gridview.datasource to SQL table using LINQ( i am trying to learn it) or anything else at this point?
 
I have tried linq querring the gridview and got a bit farther(maybe not). I get all the rows from the gridview, but they are empty. Will have to figure out what else is missing.

Here is the code:

VB.NET:
        Dim db As New commissionsDataContext
        Dim quer = From datas In GridView1.Rows
                   Select New gcstransaction()

        db.gcstransactions.InsertAllOnSubmit(quer)
        db.SubmitChanges()
 
Back
Top