Winan,
>>mydatarow = MainForm.DataSet11.Tables("Table1").NewRow ' The Error occurs here
>But I meet "Object not set .. " error .. am I missing something? I think you're missing instantiating the MainForm property. I'm assuming that you want to do something like this where you pass the reference to Form1 into Form2 as a parameter:
Public Class Form2
Inherits System.Windows.Form
Private _MainForm as Form1
Public Property MainForm as Form1
Get
Return _MainForm
End Get
Set (aValue as Form1)
_MainForm = aValue
End Set
End Property
Public Sub New(o As Form1)
Me.MainForm = o
End Sub 'New
End Class 'Form2
Maybe this isn't quite what you had in mind, but you somehow have to instantiate MainForm, and you've missed that step.
~~Bonnie
>In Form1 I had 2 objects: DataSet11 and Oledbdataadapter1
>If in the same form, I can update database via dataset by using below codes:
>
>Dim mydatarow As DataRow
>mydatarow = DataSet11.Tables("Table1").NewRow
>mydatarow("test1") = TextBox1.Text
>mydatarow("test2") = TextBox2.Text
>mydatarow("test3") = TextBox3.Text
>DataSet11.Tables("Table1").Rows.Add(mydatarow)
>OleDbDataAdapter1.Update(DataSet11, "Table1")
>
>But, what I need is to update the database via the other form, let say Form2
>
>In Form2 I had
>
>Private _MainForm as Form1
>
>Public Property MainForm as Form1
> Get
> Return _MainForm
> End Get
> Set (aValue as Form1)
> _MainForm = aValue
> End Set
>End Property
>
>then I change the codes to:
>
>Dim mydatarow As DataRow
>mydatarow = MainForm.DataSet11.Tables("Table1").NewRow ' The Error occurs here
>mydatarow("test1") = TextBox1.Text
>mydatarow("test2") = TextBox2.Text
>mydatarow("test3") = TextBox3.Text
>MainForm.DataSet11.Tables("Table1").Rows.Add(mydatarow)
>MainForm.OleDbDataAdapter1.Update(MainForm.DataSet11, "Table1")
>
>But I meet "Object not set .. " error .. am I missing something? I need advice .. thanks a lot in advance
>
>regards
>Winanjaya