This is my first attempt in .NET creating a form app and I'm having a little bit of difficulty grasping the concept of the DataSource/TableAdapter/Query/Fill/GetBy/etc. relationships.
I have a form with a bunch of textboxes and a couple of checkboxes that act as spec input to configure a product. The product type is selected with a combobox, "cmbProduct". I have a SQL table, "UserInputs", that I want to use to pre-fill the form with the specs that the user entered for the previous configuration of that product. The table will have a unique record for each user/product combination.
I have created a dataset we'll call "myDataSet".
I have created a TableAdapter, "UserInputsTableAdapter". I set the "main" SQL query to simply be (select * from UserInputs) and VS created Fill() and GetBy() methods for me.
I added a SQL query to the TableAdapter to pull the desired record.... (select * from UserInputs where username = @username and product = @product). This also created methods, which I named FillByUserAndProgram() and GetDataByUserAndProgram().
I pulled up the DataSet designer and from my TableAdapter dragged-n-dropped my fields onto their respective controls.
In my form_load I have:
I also have the same FillBy in the event handler for the combobox change...
This all seems to work fine, visually, although I may be setting it up wrong. Whenever I change the selection in the combobox, all of my fields are populated with the appropriate data from UserInputs.
At this point, the user may obviously change some of these fields, and I'd like to write those changes back to the record once they submit the form. This is where my confusion with the relationship and connection between the data in my form and the actual record in my database comes in.
My assumption was that after the fields had been changed that I could simply do this...
But the Update method is asking for a (dataRow as System.Data.DataRow) object as a parameter. Am I supposed to be creating a dataRow object somewhere? Should I be using the GetDataBy method to retrieve the record to begin with? Any help is appreciated.
Thanks,
Chris
I have a form with a bunch of textboxes and a couple of checkboxes that act as spec input to configure a product. The product type is selected with a combobox, "cmbProduct". I have a SQL table, "UserInputs", that I want to use to pre-fill the form with the specs that the user entered for the previous configuration of that product. The table will have a unique record for each user/product combination.
I have created a dataset we'll call "myDataSet".
I have created a TableAdapter, "UserInputsTableAdapter". I set the "main" SQL query to simply be (select * from UserInputs) and VS created Fill() and GetBy() methods for me.
I added a SQL query to the TableAdapter to pull the desired record.... (select * from UserInputs where username = @username and product = @product). This also created methods, which I named FillByUserAndProgram() and GetDataByUserAndProgram().
I pulled up the DataSet designer and from my TableAdapter dragged-n-dropped my fields onto their respective controls.
In my form_load I have:
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'...'
pUser = GetUserName
UserInputsTableAdapter.FillByUserAndProgram(myDataSet.UserInputs, pUser, cmbProduct.SelectedValue)
End Sub
I also have the same FillBy in the event handler for the combobox change...
VB.NET:
Private Sub cmbProduct_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbProduct.SelectedIndexChanged
UserInputsTableAdapter.FillByUserAndProgram(myDataSet.UserInputs, pUser, cmbProduct.SelectedValue)
End Sub
This all seems to work fine, visually, although I may be setting it up wrong. Whenever I change the selection in the combobox, all of my fields are populated with the appropriate data from UserInputs.
At this point, the user may obviously change some of these fields, and I'd like to write those changes back to the record once they submit the form. This is where my confusion with the relationship and connection between the data in my form and the actual record in my database comes in.
My assumption was that after the fields had been changed that I could simply do this...
VB.NET:
UserInputsTableAdapter.Update()
But the Update method is asking for a (dataRow as System.Data.DataRow) object as a parameter. Am I supposed to be creating a dataRow object somewhere? Should I be using the GetDataBy method to retrieve the record to begin with? Any help is appreciated.
Thanks,
Chris