jackjohnson44
asked on
dataadapter datagridview
I want to fill a datagridview, enter data into it, then save the data back to the database.
It should be pretty simple, but I can't get it to work.
I was using another post, but all the comments were getting cluttered and no one was answering the question. It is pretty important, I have been struggling for days. If you want to see the other question, it is here: https://www.experts-exchange.com/questions/22044293/vb-net-dataadapter-update-and-datagridview.html
select * from users
ID (auto increment), username, password
It should be pretty simple, but I can't get it to work.
I was using another post, but all the comments were getting cluttered and no one was answering the question. It is pretty important, I have been struggling for days. If you want to see the other question, it is here: https://www.experts-exchange.com/questions/22044293/vb-net-dataadapter-update-and-datagridview.html
select * from users
ID (auto increment), username, password
ASKER
thanks, but my problem was mostly with updating the database after tying something into my dataview. Can you please show how to do that?
ahhh, i always do this... i see the issue i the other post and i completely missed the idea of the post. to be completely honest, i would only use datagrid for viewing only and create totally separate small forms to add data and simply refresh on me.close.
ASKER
I thought the datagrids were made to do what I am saying.
They have the data members to do this, yes, but i would programatically move around this functionality. The only reason i could think of someone needing to have this access is in an admin situation. If users are allowed this funationality then the data is vunerable and may start showing anomalies based on inconstent data when 'many' users access this at the same time. I have not read the entire thread in other forum and didnt read the 'save back to database" part in the original post. you have many experts following through and they should be able to provide extensive answers as well as advice.
When i posted, i just knew how to fill a datagridview and manipulate the data going in. That's all! Once upon a time, I tinkered around with the functionailty of the Datagrid members. Now i do manual builds and the data is manipulated using forms.
sry&gl,
Lucas
When i posted, i just knew how to fill a datagridview and manipulate the data going in. That's all! Once upon a time, I tinkered around with the functionailty of the Datagrid members. Now i do manual builds and the data is manipulated using forms.
sry&gl,
Lucas
ASKER
thanks
so you would display data in the grid and enter it in a different way?
so you would display data in the grid and enter it in a different way?
jj,
sure. i would set the datagridview to readonly and only allow them to search thru refreshing (dynamic sql build) and create a seperate form to add, modify and delete. That way you control the data more effeciently and less oppurnity for mistakes. i have done it like this many times.
Lucas
sure. i would set the datagridview to readonly and only allow them to search thru refreshing (dynamic sql build) and create a seperate form to add, modify and delete. That way you control the data more effeciently and less oppurnity for mistakes. i have done it like this many times.
Lucas
ASKER
thanks, one more quick question:
Why did you specifu the auto increment?
Does this do anything to the dataset?
select * from users ID (auto increment), username, password
Why did you specifu the auto increment?
Does this do anything to the dataset?
select * from users ID (auto increment), username, password
jj,
i think binding the data to a form is going to be you best bet. If you have trouble doing this, then read through the link below...
http://www.startvbdotnet.com/ado/simplebinding.aspx
It is a very good discussion/tutorial on binding data to a form. Once you have the form, simply put a button on the form to fill a datagridview.
OR, lol just thought of this. You can set a refresh routine so that on the bottom of the form, below your binded data, a datagridview could be present. Everytime you update, insert or delete, you can refresh the datagrid to give realtime views.
Lucas
i think binding the data to a form is going to be you best bet. If you have trouble doing this, then read through the link below...
http://www.startvbdotnet.com/ado/simplebinding.aspx
It is a very good discussion/tutorial on binding data to a form. Once you have the form, simply put a button on the form to fill a datagridview.
OR, lol just thought of this. You can set a refresh routine so that on the bottom of the form, below your binded data, a datagridview could be present. Everytime you update, insert or delete, you can refresh the datagrid to give realtime views.
Lucas
I just copied the SQL string you had in original post. Thats all!
Lucas
Lucas
Should have been
"select ID , username, password from users"
"select ID , username, password from users"
Dim cm As CurrencyManager
Private Sub yourForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
yourDataAdapter.Fill(yourD ataSet, "yourTable")
yourDataGrid.DataSource = yourDataSet.Tables("yourTa ble")
cm = CType(BindingContext(yourD ataSet.Dat aSource), CurrencyManager)
Dim cb As Oledb.oledbCommandBuilder = New oledb.oledbCommandBuilder( yourDataAd apter)
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
yourDataAdapter.Update(you rDataSet, "yourTable")
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
cm.EndCurrentEdit()
cm.RemoveAt(cm.Position)
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
cm.EndCurrentEdit()
cm.AddNew()
End Sub
Private Sub yourForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
yourDataAdapter.Fill(yourD
yourDataGrid.DataSource = yourDataSet.Tables("yourTa
cm = CType(BindingContext(yourD
Dim cb As Oledb.oledbCommandBuilder = New oledb.oledbCommandBuilder(
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
yourDataAdapter.Update(you
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
cm.EndCurrentEdit()
cm.RemoveAt(cm.Position)
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
cm.EndCurrentEdit()
cm.AddNew()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Mine won't update!
If not, do this....
Dim myTable As New DataTable
Dim cmdFillForm As New OleDb.OleDbDataAdapter("se
cmdFillForm.Fill(myTable)
dgViewUsers.DataSource = myTable
dgViewUsers being the drag and drop datagridview component.
This will simply display the select in a datagridview. Very simple and can be modified. You can also label static information for the column headers. play around with this, then modify.
gl,
Lucas