SQL Data Adapter and Visible

  • Thread starter Brian P. Hammer
  • Start date
B

Brian P. Hammer

All,
I have a few text boxes on a form that have several data entry points using
a SQL data adapter. I hide a couple of these text boxes that collect hidden
information like user name and date created. When these controls are hidden
on the form, the information in the text boxes is not added to my SQL table
but if I unhide them, It collects the data and populates the table. What am
I missing?

Thanks,
 
S

Scot Rose [MSFT]

If you make the textboxes visible does it update? How are you entering the data into the controls? Something like Textbox1.text="MyData". It sounds like something to do with the
Binding context or perhaps you have to call an EndEdit on the field...

Do you have a small sample that reproduces the problem that you could send to me to take a look at?

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.




--------------------
 
B

Brian P. Hammer

Hi Scott,

Thanks for the answer. I attached a zip file with a test project sent to
your email. I based it off the Northwind SQL for this example.

To reproduce the problem this is what I do.

1. Select add

2. Add in a new product name

3. Update the record

Everything turns out great.

1. select add

2. Add in a new product

3. Click on hide

4. Update the record

This will generate an error on this example because the the field doesn't
accept nulls. But in any case, it does not grab the data from the statement
of me.textbox3.text = "10" when it is hidden. But if it is unhidden, it
works.

What am I doing worng here.

Thanks,

Brian P. Hammer
 
B

Brian P. Hammer

I'll try this, but to add to this issue...

If I have a hidden text box such as an ID number and I try to pass the value
to another form, I get errors as well if it's hidden but it works great if
it is not hidden. But, it is not just that simple. If I unhide the text
box and then rehide it, it will see the value and pass the value.

So, in this case, I don't think using .Modified=True will solve the problem.

It just seems to me that if an item is hidden, VB doesn't "see" it.

The sample was sent again to the correct email.

--
Brian P. Hammer
I found this looking for another answer this morning but it may be what is
going on in your case as well...

Try setting Textbox1.Modified=True after setting the contents... Look at the
documentation for Modified in the Help files (TextBoxBase.Modified Property)
where it says:

You can use this property to determine if the user has modified the contents
of the text box control. You can also set this property in code to indicate
that changes were made to the
text box control by the application. This property can be used by validation
and data-saving methods to determine if changes were made in a text box
control so the changed
contents can be validated or saved.

Very similar to the DataChanged property in VB6


Basically, after setting teh contents of the textboxes from code, set teh
modiied property to true. This does not get set unless you TYPE into the
text box... Please let me know if this
is the answer for you as I would like to know this for future reference<G>

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com
or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided "AS IS", with no warranties, and confers no rights.




--------------------
 
S

Scot Rose [MSFT]

Brian, Got your sample code and dude, hidden or unhidden it works on my machine... What version of VS and OS and service packs do you have installed so I can get as close to
your system as possible here...

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.




--------------------
 
B

Brian P. Hammer

To add a bit, I look in add/remove programs, and I see .Net Framework, 1.1
..Net Framework. So do I have 1 or 1.1?

--
Brian P. Hammer
Brian, Got your sample code and dude, hidden or unhidden it works on my
machine... What version of VS and OS and service packs do you have installed
so I can get as close to
your system as possible here...

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com
or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided "AS IS", with no warranties, and confers no rights.




--------------------
From: "Brian P. Hammer" <[email protected]>
References: <OwG#[email protected]>
<6pUy#[email protected]>
 
B

Brian P. Hammer

Scot,



Here is another example (Sent to email). I think I might have jumped the
gun a bit. Here is how to reproduce the problem.



Run VS and make sure textbox3 is visible

Create a new record

Save the record

This should work properly



Now,

Open VS and make textbox3 is NOT visible via the properties

Create a new record

Save the record

This should reproduce the problem.



I added the Hide and Unhide buttons and select them and it seems to work as
expected. But, If I have property set to visible = false and then save a
record and unhide using the command button, no entry is made.



If anyone else is interested in looking at this issue, you can download the
source at http://www.caap.com/testhide.zip





Thanks,


--
Brian P. Hammer
All,
I have a few text boxes on a form that have several data entry points using
a SQL data adapter. I hide a couple of these text boxes that collect hidden
information like user name and date created. When these controls are hidden
on the form, the information in the text boxes is not added to my SQL table
but if I unhide them, It collects the data and populates the table. What am
I missing?

Thanks,
 
S

Scot Rose [MSFT]

Brian, Basically it looks as though the Textbox is not finished initializing (Perhaps something in its paint events) if you have the Visible set to False at desighn time... If you change
the form Load to this

DsCompany1.Clear()
SqlDataAdapter1.Fill(DsCompany1, "Customers")
TextBox3.Refresh()

(Note the Textbox Refresh) then it does work. The same is true if you do teh refresh after changing the data (But that would refresh each time, when you really only need to do it
once) It appears the Refresh forces the control to complete whatever initialization is failing otherwise...

Another option as you have found is to not set the control at design time, but at runtime in the form load event.

Want to know more? Check out the MSDN Library at http://msdn.microsoft.com or the Microsoft Knowledge Base at http://support.microsoft.com

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.




--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top