What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue? What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
Go Back  Xtreme Visual Basic Talk > > > What Would Cause this Text Box Issue?


Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2004, 06:12 AM
DaFlugster DaFlugster is offline
Freshman
 
Join Date: Jun 2004
Location: Parkersburg, WV
Posts: 34
Question What Would Cause this Text Box Issue?


Using the OLEDB Feature I "Fill" the database When the Form is loaded, (Access DataBase Table). When I clear the text boxes, to either "ADD" a new Row or to edit the data using the following code:

Private Sub frmBrowse_Load()
dbScanner.Fill(DsScanInfo1, "ScanInfo") ' Fill Data Base
End Sub

Private Sub ClearTextBoxes()
txtBN.Clear()
txtEmp.Clear()
txtEmpId.Clear()
txtSupervisor.Clear()
End Sub

The Text Boxes do Clear, however if I "TAB" through the Text boxes the Data reappears in the text boxes. The Twist is that only the Data that is numeric in value Will reappear. The Alpha text Boxes do not Reappear. What am I doing wrong or what else do I need to do?
Reply With Quote
  #2  
Old 08-18-2004, 08:31 AM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Are you using any databindings or are these unbound text boxes that you are being sent values via their .text property?
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #3  
Old 08-18-2004, 12:27 PM
DaFlugster DaFlugster is offline
Freshman
 
Join Date: Jun 2004
Location: Parkersburg, WV
Posts: 34
Default

Quote:
Originally Posted by MKoslof
Are you using any databindings or are these unbound text boxes that you are being sent values via their .text property?
I set the DataBindings on each text box in its Properties under Databindings/Text. However, no where in my code do I use DataBind()
Reply With Quote
  #4  
Old 08-18-2004, 07:12 PM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

So you do nothing at runtime regarding your dataBindings? So, if you clear the dataset and assign a new dataset, how does this effect your dataBindings. Since you have defined a default databinding at runtime, these databindings are still associated with the text boxes. And, since you have no code at runtime to reassociate or change these databindings, I am not sure of their relevance in your application.

If you want to clear any known databindings for a given text box object, try:

Code:
Me.TextBox2.DataBindings.Clear()
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #5  
Old 08-19-2004, 07:02 AM
DaFlugster DaFlugster is offline
Freshman
 
Join Date: Jun 2004
Location: Parkersburg, WV
Posts: 34
Default

Quote:
Originally Posted by MKoslof
So you do nothing at runtime regarding your dataBindings? So, if you clear the dataset and assign a new dataset, how does this effect your dataBindings. Since you have defined a default databinding at runtime, these databindings are still associated with the text boxes. And, since you have no code at runtime to reassociate or change these databindings, I am not sure of their relevance in your application.

If you want to clear any known databindings for a given text box object, try:

Code:
Me.TextBox2.DataBindings.Clear()
As I have stated before I am new to VB and am trying to develope this simple Application, by using text books and other reference books. I do not know what else I should have to do with the DataBindings, since I declared them at design time? I tried your code example and it seemed to work (the text did not reappear after tabbing through the fields). However, I lost my "bind" on those fields, No Data in any fields when navigate through the data and I have tried to figure out how to reassign the bind back. I have attached a Screen shot of the window that I am working with, it is a "Simple" Program I am trying to develope (Just Add, modify, and delete Records(Rows) in a Access table.)

It seems the more I change the worse it gets... I am now getting This Error: "Uhandled Exception of Type 'System.Stackoverflow Exception' in System.Windows.forms.dll" on the following code:

Code:
Private Sub cboSN_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboSN.SelectedIndexChanged Me.BindingContext(DsScanInfo1, "ScanInfo").Position = cboSN.SelectedIndex CheckAssign() RecordCount() End Sub

Any light that can be shed would be appreciated.
Attached Images
File Type: jpg Screen Shot.jpg (88.1 KB, 5 views)
Reply With Quote
  #6  
Old 08-23-2004, 03:57 PM
scalijdub scalijdub is offline
Newcomer
 
Join Date: Aug 2003
Posts: 20
Default Setting Null to the databound textbox

I can not seem to get a text box bound to a dataset accept a null value. It automatically reverts to the previous data. Any ideas because I've searched around for 2 hours now.
Reply With Quote
  #7  
Old 08-23-2004, 04:49 PM
scalijdub scalijdub is offline
Newcomer
 
Join Date: Aug 2003
Posts: 20
Default

I'm having the same issue, however, I understand what he is saying. Basically your clearing the "magic" code associated with bindings and you are not reconnecting them.

You can also fix this with setting the text box's causes validation to false also, however, when you try to save a null value it will replace that data with what was previously there.

So far its very freaking annoying and ****ing me off greatly.
Reply With Quote
  #8  
Old 08-23-2004, 05:06 PM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

The first button click populates a dataset and sets databindings..the second clears all relations and sets the text boxs to blank

Code:
Dim ds As New DataSet Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cn As New OleDbConnection(conn_string) Dim da As New OleDbDataAdapter("Select f1, f2, f3, field4 from myTable", cn) ds = New DataSet 'add both tables and build a relationship da.Fill(ds, "myTable") 'bind text box and other controls TextBox1.DataBindings.Add("Text", ds.Tables!myTable, "F1") TextBox2.DataBindings.Add("Text", ds.Tables!myTable, "F2") TextBox3.DataBindings.Add("Text", ds.Tables!myTable, "F3") TextBox4.DataBindings.Add("Text", ds.Tables!myTable, "Field4") End Sub Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click Call CleanUp(ds) End Sub Private Sub CleanUp(ByVal d as DataSet) ds.clear Me.TextBox1.DataBindings.Clear() Me.TextBox2.DataBindings.Clear() Me.TextBox3.DataBindings.Clear() Me.TextBox4.DataBindings.Clear() Me.TextBox1.Text = "" Me.TextBox2.Text = "" Me.TextBox3.Text = "" Me.TextBox4.Text = "" End Sub
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #9  
Old 08-24-2004, 06:39 AM
DaFlugster DaFlugster is offline
Freshman
 
Join Date: Jun 2004
Location: Parkersburg, WV
Posts: 34
Default

Quote:
Originally Posted by MKoslof
So you do nothing at runtime regarding your dataBindings? So, if you clear the dataset and assign a new dataset, how does this effect your dataBindings. Since you have defined a default databinding at runtime, these databindings are still associated with the text boxes. And, since you have no code at runtime to reassociate or change these databindings, I am not sure of their relevance in your application.

If you want to clear any known databindings for a given text box object, try:

Code:
Me.TextBox2.DataBindings.Clear()
When I use the suggested code it works in clearing the Bind of the fields, but how dow I re-assign the binding. After clear the fields, I no longer have the capability to scroll through the Data. The Attachment on the previous post shows the window that is in question.
Reply With Quote
  #10  
Old 08-24-2004, 07:57 AM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

If you clear the bindings you have to recreate them . You can't have it both ways. If you want to clear a dataset and clear the databindings within a control, and then you want to repopulate with a new dataset and new databindings, you have to create an event to do this for you.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #11  
Old 08-24-2004, 09:51 AM
scalijdub scalijdub is offline
Newcomer
 
Join Date: Aug 2003
Posts: 20
Default

Doesnt that completely make dataset binding irrelevent? If i have to hand code the load, and the save to accept null values then why would I ever bother to use databinding?

Basically you are saying to ether clear the dataset or the databindings, do what you do and then rebinding everything. Wouldn't rebinding the control over write what is currently stored?
Reply With Quote
  #12  
Old 08-24-2004, 10:00 AM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

But don't you want to clear the DataBindings from the Text box? So, if you clear the dataset what do you want to display in the text box? So you want to display a null text box but still keep the databindings? So if there is a record in the DataSet just ignore it and use Null instead? That also defeats the purpose of dataBinding. You are binding a control to a dataSource. If want to clear this binding, you can via the control's databindings .clear method. If you don't want to clear the controls databindings, why would you have a null value in a bound control?

When you say "overwrite what is currently stored" I don't understand how that relates to clearing a dataBinding. If you Clear a dataset, the data within that Dataset is gone. So, if you want to clear a binding for a control, you are removing anything that is currently in use within that control's binding.

Then, if you want to repopulate, call a function, set your bindings again..because I assume you want NEW databindings this time (a different recordset, different fields).
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown

Last edited by MKoslof; 08-24-2004 at 10:06 AM.
Reply With Quote
  #13  
Old 08-24-2004, 10:18 AM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

OK, I have merged these two threads since they are similiar, just so I properly understand, which of these scenerios are you trying to accomplish:

1) Clear an existing dataset and bind the text boxes to a new DataSet (so clear all bindings and start fresh)
2) Do not clear the databindings at all, but show null values in my text boxes (If so, do you want to ADD NEW null values to your database table?)
3) Do not clear the DataSet, but clear the Databindings in the text box (If so, if you want to re-bind the text boxes, will you be re-connecting the same dataset, a new one)
4) Edit existing DataBindings, set a field in the table to null.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #14  
Old 08-24-2004, 10:46 AM
scalijdub scalijdub is offline
Newcomer
 
Join Date: Aug 2003
Posts: 20
Default

This is what I am trying to do.
I have 3 fields in my database.
When I load the dataset it displays the data into 3 text boxes.
When I want to update the data in text box one, I change the value and hit update and it works. (I.E. changing from 1/1/2003 to 1/1/2004)
When i want to update the same textbox to no value it does not work. (I.E. changing from 1/1/2003 to "") when i hit update it automatically reverts to 1/1/2003.

If i were to databindings.clear it breaks the connection the dataset and does not update.
If i were to clear the databindings and then reconnect them before i update it overwrites the changes.
If i were to clear the dataset it empties all the text boxes.

All I want to do is beable to have an empty text box update to the database. So if I have 3 text boxes for the name John, D, Smith and then the user decideds he doesnt want to use the middle initial and clears the value, "D", in the textbox and hits update, it will save a null value or blank in the database.
Reply With Quote
  #15  
Old 08-24-2004, 10:54 AM
DaFlugster DaFlugster is offline
Freshman
 
Join Date: Jun 2004
Location: Parkersburg, WV
Posts: 34
Default

Quote:
Originally Posted by MKoslof
OK, I have merged these two threads since they are similiar, just so I properly understand, which of these scenerios are you trying to accomplish:

1) Clear an existing dataset and bind the text boxes to a new DataSet (so clear all bindings and start fresh)
2) Do not clear the databindings at all, but show null values in my text boxes (If so, do you want to ADD NEW null values to your database table?)
3) Do not clear the DataSet, but clear the Databindings in the text box (If so, if you want to re-bind the text boxes, will you be re-connecting the same dataset, a new one)
4) Edit existing DataBindings, set a field in the table to null.
In my application I wish to do option 4 in your quote. If Scanner ID 334058 is assigned to a user and it breaks or needs to be repaired, I have to 'Clear' or unassign the Scanner and assign the user a new scanner ID. I think scalijdub is having a similiar issue.

Therefore I want to "Edit" the assignment informatin to be blank or Null Values. Before when I would just use
Code:
txtbn.text = ""
or
Code:
txtbn.clear()

the "data" would clear from the text box, but if I would tab through the field the data exiting data would appear.
Reply With Quote
  #16  
Old 08-24-2004, 01:55 PM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

OK, here is an example I drew up. This uses the currency manager to navigate the DataSet. Basically I have two text boxes on a form and several buttons

1) Fill the dataset and set the initial bindings
2) Move First
3) Move Next
4) Move Previous
5) AddNew

Notice in the add new button I send one of the fields a DBNull value. This add the new entry automatically. Now hit the first button again to start over..go through each record..notice the last record, or the last one just entered, now has a null value.

Code:
Public Const conn_string As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Testing.mdb;Persist Security Info=False" Dim ds As New DataSet Dim cm As CurrencyManager Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cn As New OleDbConnection(conn_string) Dim da As New OleDbDataAdapter("Select EmpID, Sales From myTable", cn) 'add both tables and build a relationship da.Fill(Me.ds, "myTable") 'bind text box and other controls TextBox1.DataBindings.Add("Text", ds.Tables!myTable, "EmpID") TextBox2.DataBindings.Add("Text", ds.Tables!myTable, "Sales") 'bind the currencymanager cm = CType(Me.BindingContext(ds.Tables!myTable), CurrencyManager) End Sub Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click 'move first If Not (cm Is Nothing) AndAlso cm.Count Then cm.Position = 0 End Sub Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click 'move next If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position < cm.Count - 1 Then cm.Position += 1 End Sub Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click 'move previous If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position > 0 Then cm.Position -= 1 End Sub Private Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click 'add new cm.AddNew() Dim drv As DataRowView drv = CType(cm.Current, DataRowView) drv.Item("EmpID") = DBNull.Value drv.Item("Sales") = 99999 cm.EndCurrentEdit() End Sub
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #17  
Old 08-24-2004, 02:18 PM
scalijdub scalijdub is offline
Newcomer
 
Join Date: Aug 2003
Posts: 20
Default

Yes, I but that only works in a very limited application. If i were to use that I would be forced to still do the standard
if txt.text = "" then
drv.item("f1") = dbnull.value
else
drv.item("f1") = txt.text
end if

I am quickly finding out when I google databinding bugs why so many programmers think databinding is the devil.
Reply With Quote
  #18  
Old 08-24-2004, 02:24 PM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

So is your question now, do you have to check for an empty string within an If construct. Well, you are going to have to check for an empty value either way. But you can condense it within one call:

Code:
drv.item("f1") = IIF(Txt.Text = "", dbNull.Value, txt.Text) drv.item("F2") = IIF(Txt1.Text = "", dbNull.Value, txt1.Text)

So you are assigning your values in a standard manner, just wrap it in an IIF conditional. If you have 10 items to add, either way you are listing them out..so just wrap them in an IIF construct, then you don't have to worry about calling an IF/Else everytime. Or just condense this into one function that you call over and over again.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #19  
Old 08-30-2004, 03:40 PM
scalijdub scalijdub is offline
Newcomer
 
Join Date: Aug 2003
Posts: 20
Default

I think i fixed it and it is working here. Could you take a look and do a test run with it.
1. build a dataadapter.
2. generate a dataset.
3. set your parameters
4. set your connection
5. set your dataadapter
6. name your table
7. Query your database (aka Execute")


///////////////////////// found in the form

Code:
public sub test() Me.daPatient.SelectCommand.Parameters(0).Value = 1 pado.Connection = Me.ConnC pado.DataAdapter = Me.daPatient pado.DataSet = Me.DsPatient1 pado.TableName = "tblpatient" pado.Query() Me.lbllast.Text = pado.Field("fldp_last") Me.lblfirst.Text = pado.Field("fldp_first") Me.lbldob.text = pado.field("fldp_dob") pado.field("fldp_first") = "Try" pado.field("fldp_last") = "Me" pado.Field("fldp_dob") = "" pado.Update() end sub /////////////////// new class //////////////////// Option Explicit On Option Strict On Imports System.Data.OleDb Public Class clsado2005 Private pConn As New System.Data.OleDb.OleDbConnection 'property Private pDA As New System.Data.OleDb.OleDbDataAdapter 'property Private pDT As DataTable 'property Private pDS As New DataSet 'property Private pTablename As String 'property Private pPosition As Integer 'property Private pFoundRows() As DataRow Private pCM As CurrencyManager Property Connection() As System.Data.OleDb.OleDbConnection Get Return pConn End Get Set(ByVal Value As System.Data.OleDb.OleDbConnection) pConn = Value End Set End Property Property DataTbl() As DataTable Get Return pDT End Get Set(ByVal Value As DataTable) pDT = Value End Set End Property Property TableName() As String 'the table name Get Return pTablename End Get Set(ByVal Value As String) pTablename = Value End Set End Property Property DataAdapter() As System.Data.OleDb.OleDbDataAdapter Get Return pDA End Get Set(ByVal Value As System.Data.OleDb.OleDbDataAdapter) pDA = Value End Set End Property Property DataSet() As DataSet Get Return pDS End Get Set(ByVal Value As DataSet) pDS = Value End Set End Property Property Field(ByVal Column As String) As String Get Try Return CStr(IIf(Me.pDT.Rows(pPosition).IsNull(Column) = True, "", pDT.Rows(pPosition).Item(Column))) Catch ex As Exception End Try End Get Set(ByVal Value As String) If Value <> "" Then pDT.Rows(pPosition).Item(Column) = Value Else pDT.Rows(pPosition).Item(Column) = DBNull.Value End If End Set End Property ReadOnly Property ReturnedDR() As DataRow 'Works like a recordset Get Return pDT.Rows(pPosition) End Get End Property ReadOnly Property Foundrows() As DataRow() Get Return pFoundRows End Get End Property Property Position() As Integer 'Returns the index of the row within the datatable/dataset Get Return pPosition End Get Set(ByVal Value As Integer) pPosition = Value End Set End Property ReadOnly Property RecordCount() As Integer Get Return Me.pDT.Rows.Count() End Get End Property ReadOnly Property BOF() As Boolean Get If Me.pDT.Rows.Count = 0 Then Return True Else Return False End If End Get End Property ReadOnly Property EOF() As Boolean Get If Position = Me.pDT.Rows.Count Then Return True Else Return False End If End Get End Property Public Sub New() pDA = New OleDbDataAdapter pDS = New DataSet End Sub Public Sub Query() Dim myCommand As OleDbCommandBuilder Try pDA.SelectCommand.Connection.ConnectionString = Me.pConn.ConnectionString pDA.Fill(pDS, Me.pTablename) pDT = pDS.Tables(Me.pTablename) Catch Console.WriteLine("Error Opening {0}", pConn.DataSource) End Try myCommand = New OleDbCommandBuilder(pDA) End Sub Public Sub Update() Try Dim newDataSet As DataSet newDataSet = pDS.GetChanges() pDA.Update(newDataSet, Me.pTablename) pDS.Tables(Me.pTablename).AcceptChanges() Catch ex As Exception Console.WriteLine(ex) End Try End Sub end class

Edit by mkoslof: Added vb tags

Last edited by MKoslof; 08-30-2004 at 05:31 PM.
Reply With Quote
  #20  
Old 08-30-2004, 05:32 PM
MKoslof's Avatar
MKoslofWhat Would Cause this Text Box Issue? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Looks good
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue? What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue? What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
 
What Would Cause this Text Box Issue?
What Would Cause this Text Box Issue?
 
-->