DonnaF Posted August 26, 2003 Posted August 26, 2003 I have a database with multiple tables. I want to be able to update different tables on different forms (using VB.Net). Do I need to set up an connection, data adapter and dataset for each form? I would guess that if I'm accessing different tables, that I would at least need to set up different dataset on each form. What about the connection and data adapter? Also, if I access data from one table on a form, can I pass that data to another form? I'm fairly new to processing with databases, so I wasn't sure how this would work. Thanks, Donna Quote
Mehyar Posted August 26, 2003 Posted August 26, 2003 Donna It is enough that you declare the dataset and the dataadapoters as public in Form1 and then access them from the other forms on condition you open the other forms from form1. From within form1 when you want to open form2 Dim f as new Form2() Me.AddOwnedForm(f) f.showDialog() or f.Show() Now from within form2 you can access the dataset and the data adapters by : Ctype(Me.Owner,Form1).theDataSetNameYouChose Ctype(Me.Owner,Form1).theDataAdapterNameYouChose Hope this helps Quote Dream as if you'll live forever, live as if you'll die today
DonnaF Posted August 26, 2003 Author Posted August 26, 2003 When I dragged the data adapter, and dataset onto the form, it generated the following in the Windows Form Designer generated code: Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbDeleteCommand1 As System.Data.OleDb.OleDbCommand Friend WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter Friend WithEvents DataSet1 As System.Data.DataSet <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() In order to declare the dataset and data adapter as public, do I need to change Friend WithEvents to Public WithEvents? I'm not familiar with how databases and multiple forms work, so I need some help understanding this. Also, you said I needed to open the other forms from form1, in order to access the database. What would happen if I opened a form3 from form2, and wanted to access the database? Thanks for your help, Donna Quote
Mehyar Posted August 27, 2003 Posted August 27, 2003 As you said simply change the Friend to Public... As for being not familiar with databases and multiple forms... This is a scenario of a database with one form (in this case form1) you are only accessing the data adapters of form1 from other forms, so when you need to update the adapter to the database it is the same as having it in one form. You would access the dataset from form2 as i showed you Ctype(Me.Owner,Form1).DataSet1 Ctype(Me.Owner,Form1).OleDbDataAdapter1 Now if you want to open form3 from form2 then you would open form 3 as you opened form2 from form1 In form2 type this when you want to open form3 Dim f as new Form3() Me.AddOwnedForm(f) f.showDialog() or f.Show() Now in order to access the dataset and the dataadapters from form3 you have to reference its owner (Form2) and then the owner of Form2 which is form1. Ctype(Me.Owner,Form2).Ctype(Me.Owner,Form1).DataSet1 Ctype(Me.Owner,Form2).Ctype(Me.Owner,Form1).OleDbDataAdapter1 Quote Dream as if you'll live forever, live as if you'll die today
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.