Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating database via dataset from other form
Message
From
23/05/2004 01:11:03
 
 
To
22/05/2004 21:45:56
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00906274
Message ID:
00906285
Views:
19
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
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform