Hello,
Im currently having trouble trying to bind mssql table to some fields on a test app.
Basicly i have my text fields, buttons, dataset though unsure if ive made my dataset correctly. Below this is my code, though ive not worked out update, add, delete as yet.
I know I prob dont have enough information on here, but am I in the correct direction and why would it not work, it does not error on a click event just does nothing. Do I have to refill it the text fields are binded to this dataset the first record shows.
Please help, and try to keep the answer to a rooks standard please, thank you.
PS: Any links with visual dataset setup would be great too, so that i can confirm that I'm doing it correctly.
--------------------------------------------------------------------------------------------------------
Private Sub btn_update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_End.Click Try Me.BindingContext(Me.DataSet1.Table11, "ID").Position = Me.BindingContext(Me.DataSet1.Table11, "ID").Count - 1 Catch ex As ExceptionMessageBox.Show(ex.ToString,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btn_load_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_load.Click Me.Table11TableAdapter.Fill(Me.DataSet1.Table11) End Sub Private Sub btn_next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_next.Click Try Me.BindingContext(Me.DataSet1.Table11, "ID").Position += 1 Catch ex As ExceptionMessageBox.Show(ex.ToString,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btn_first_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_first.Click Try Me.BindingContext(Me.DataSet1.Table11, "ID").Position = 1 Catch ex As ExceptionMessageBox.Show(ex.ToString,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btn_last_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_last.Click Try Me.BindingContext(Me.DataSet1.Table11, "ID").Position -= 1 Catch ex As ExceptionMessageBox.Show(ex.ToString,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub
VB.NET 2005 Binding / DS Help
My Vizai
Sorry,
This is the error im recieving,
Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.
Taylor Brown
Hi, it looks like you are trying to do it manually. Try the following instructions on how to use the binding source in addition to the dataset.
Hi,
First you need to create a dataset if it does not exist already. Project/Add new item/Dataset. I'll assume you call it AppData. The dataset will become the data layer of your application.
In the dataset designer, drag all your tables from the server explorer. The server explorer is accessed from View/Server Explorer. You can add a new data connection to your database (sql server, access, odbc...). Save and compile.
Create a new form. Open the Data Source pane (data/show data source) and you will see your dataset as a datasource. I'll assume you'll create a form for table Foo. Next you need to decide if you want a grid view or a detail view. Click on the Foo table in the data source window and you will see a dropdown appear. If you want a detail view instead of a grid change it with this dropdown.
Now drag the table to the empty form. You will see that a grid (or text boxes and labels) will be created with each of the fields. A BindingSource object, a binding navigator, a table adapter and an instance of your dataset are also created. Now switch to code view. You will notice in the Form_Load event some code to load the data and on the save toolstrip code to end editing and validate the data.
Let's suppose you also want to save back the changes to the database. Add this line of code:
Me.fooTableAdapter.Update(Me.appData.fooTable)
That's it. Now you have an application that can insert, delete, update and browse all the data in table Foo.
A whole bunch of good resources, including numerous books, that could really help you out:
ASP.NET 2.0: http://quickstarts.asp.net/QuickStartv20/aspnet/
Winforms: http://www.windowsforms.net/ and http://samples.gotdotnet.com/quickstart/winforms/
The online MSDN Developer's Guide for Windows Form Applications is also indispensible:
http://msdn2.microsoft.com/en-us/library/ms644558.aspx
They will all teach you the basics of databinding and data access.
Regards,
Charles
FS2K
Thanks man,
This has helped out heaps, 2005 is made a lot easier, well till you get to know it anyhow. everything worked other then removing records, I was able to add, edit, navigate as well save, though was not able to save after removing a record.
In the SaveItem_Click method, i have these 3 lines
Me.Validate() Me.Table1BindingSource.EndEdit() Me.Table1TableAdapter.Update(Me.AppData.Table1)I tryed to see if there was Me.Table1TableAdapter.Delete or Remove *** (Me.AppData.Table1) though did not see anything of use. how do i manage to get around this
Much thanks to your help before, it has made things a lot easier.
This is my form_load method
Me
.Table1TableAdapter.Fill(Me.AppData.Table1)Thanks heaps....