update datagridview not using dataset

exile07

Member
Joined
Feb 10, 2008
Messages
6
Programming Experience
1-3
Hi guys,

I'm populating a datagridview using a dataview which has been filtered. This works fine. What I've been trying to do for some time now is simply edit value in the datagridview and save these do an access database. I have tried using a dataset to update but with no success. Since I'm not using a dataset to populate the datagridview then i presume i need to use the datatable, dataadapter and dataview which i have used to populate, in order to update. I can't get this working.

VB.NET:
strConnectionString.Open()
 
        Dim tblDataTable As New DataTable("Tasks")
        daDataAdapter3.Fill(tblDataTable)

        Dim dvDataView As DataView
        dvDataView = New DataView

        dvDataView.Table = tblDataTable
        dvDataView = New DataView(tblDataTable)

        ' filter the dataview to only display invoices for this ID
        dvDataView.RowFilter = "InvoiceID =" & " " & invID & ""

        ' Bind DataView to the DataGrid
        dgTrackingCurrentInvoice.DataSource = dvDataView

        ' don't display the columns
        dgTrackingCurrentInvoice.Columns("InvoiceID").Visible = False

        ' close the connection
        strConnectionString.Close()

thanks, help would be much appreciated
 
' filter the dataview to only display invoices for this ID
dvDataView.RowFilter = "InvoiceID =" & " " & invID & ""

Aside question:
right.. WHY do people do this? why do they write a string, then concatenate a space onto the end of it? why not just put the space on the end of the first string? why do they then concatenate an empty string onto the end of the other 2 concats? i see loads of people doing this, concatenating empty strings or concatenating 2 string constants together; why?

I dont get it. This achieves the same result

dvDataView.RowFilter = "InvoiceID = " & invID

Another aside:

strConnectionString is a String, surely? How is it youre able to Open() and Close() a string?



Now.. nothing in your code actually sends the updates back to the database.. You can simply write:


daDataAdapter3.Update(tblDataTable)

the datagridview binds to a dataview, but that doesnt mean it doesnt use the underlying table to store the data.. ;) tables store data, filters and views only retrict the data, they dont store it themselves. datagridview never stores data. incidentally, when you bind a datagridview directly to a datatable, it actually uses the defaultview property of the table, which shows everythig. You can save creating a new DataView by leveraging that:

dgMyGridView.DataSource = tblMyDataTable
tblMyDataTable.DefaultView.Filter = "invoice = " & myInvoice



last point: youre using datagridview, implying .net2.0 - why are you still doing data access in the Old Way (.net 1.1 ) ?
 
Aside question:
right.. WHY do people do this? why do they write a string, then concatenate a space onto the end of it? why not just put the space on the end of the first string? why do they then concatenate an empty string onto the end of the other 2 concats? i see loads of people doing this, concatenating empty strings or concatenating 2 string constants together; why?

I dont get it. This achieves the same result

dvDataView.RowFilter = "InvoiceID = " & invID


well i just copied code i saw online. il take your info onboard though, thanks

Another aside:

strConnectionString is a String, surely? How is it youre able to Open() and Close() a string?

i called my connection string this, bad naming convention. my bad

Now.. nothing in your code actually sends the updates back to the database.. You can simply write:


daDataAdapter3.Update(tblDataTable)

the datagridview binds to a dataview, but that doesnt mean it doesnt use the underlying table to store the data.. ;) tables store data, filters and views only retrict the data, they dont store it themselves. datagridview never stores data. incidentally, when you bind a datagridview directly to a datatable, it actually uses the defaultview property of the table, which shows everythig. You can save creating a new DataView by leveraging that:

dgMyGridView.DataSource = tblMyDataTable
tblMyDataTable.DefaultView.Filter = "invoice = " & myInvoice



last point: youre using datagridview, implying .net2.0 - why are you still doing data access in the Old Way (.net 1.1 ) ?


the code i posted loads the data into the datagrid. im looking for the code to save, which would be another another button.
I've altered my code behind the save button to yours. Error now showing is
'Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.' So i need to specify which column I'm updating?
 
'Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.' So i need to specify which column I'm updating?


Table has no primary key or selection list does not include it.
 

Latest posts

Back
Top