Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataRow confusion!!!

Status
Not open for further replies.

ashishraj14

Programmer
Mar 1, 2005
92
AU
I passed DataRow in the constructor of the form2 as follow

Public Sub New(ByVal row As DataRow)
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

Then on form load event of form2, I set the text property of textbox to value from datarow as follows

txtCustID.Text = drw("Cust_ID")

When I edited value in the textbox, the changes where written back to the DataGrid. How it could happen, even though I passed row ByVal and not by ByRef?


Secondly, I tried binding DataRow to TextBox as follow

txtCustID.DataBindings.Add("Text", drw, "Cust_ID")

But, it resulted in error: "Cannot bind to property or coulmn Cust_ID on DataSource"

What am I doing wrong?

Thanks
 
Code:
Public Sub New(ByVal row As DataRow) 
MyBase.New() 

'This call is required by the Windows Form Designer. 
InitializeComponent() 

'Add any initialization after the InitializeComponent() call 

End Sub

You're not actually doing anything with the variable row here.

Code:
txtCustID.Text = drw("Cust_ID")

this line is referencing some other object. Do you have a global variable called drw?

What you probrably want to do is something like this:
Code:
private m_drRow as DataRow

Public Sub New(ByVal row As DataRow) 
MyBase.New() 

'This call is required by the Windows Form Designer. 
InitializeComponent() 

'Add any initialization after the InitializeComponent() call 

  m_drRow = Row
End Sub 

private sub Form_Load...
  txtCustID.Text = m_drRow("Cust_ID") 
  'or your binding here.
end sub

I'm not sure on the binding issue, I've never tried binding a row to an object.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top