Results 1 to 8 of 8

Thread: Textbox with databindings

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84

    Textbox with databindings

    Hi,

    In my application I'm passing a dataset ByRef with the constructor of FormWeergaveZoek. There are also four buttons to scroll through the values of the dataset (ButtonVolgend, Buttonvorig, ButtonBegin, ButtonEinde). The fields of the dataset are displayed in textboxes with databindings. All the values are displayed correctly, except Me.TextBoxCDID.DataBindings.Add("text", dsMyDataset, "tblCD.CDID") which is displaying the number of the row in the dataset and not the original number in the database. For exmple :

    In my database a CD from The Stones has CDID 234, but in the dataset (datasetzoeken12) this record is in the first row (because this is the searchresult). So the displayed result in the textbox will be 1 and not the required 234.

    Why is this????

    The code of the form is the following:


    Public Class FormWeergaveZoek
    Inherits Windows.Forms.Form
    #Region " Windows Form Designer generated code "

    Public Sub New()
    MyBase.New()

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

    'Add any initialization after the InitializeComponent() call

    End Sub

    Dim dsMyDataset As DataSet
    Public Sub New(ByRef Datasetzoeken12 As DataSet)
    MyBase.New()

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

    'Add any initialization after the InitializeComponent() call
    dsMyDataset = Datasetzoeken12
    End Sub


    Private Sub FormWeergaveZoek_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.TextBoxCDID.DataBindings.Add("text", dsMyDataset, "tblCD.CDID")
    Me.TextBoxCDDetail.DataBindings.Add("text", dsMyDataset, "tblCD.CD")
    Me.TextBox1.DataBindings.Add("text", dsMyDataset, "tblCD.programgroup")
    Me.TextBoxCDdetailDescription.DataBindings.Add("text", dsMyDataset, "tblCD.DescriptionCD")
    Me.TextBoxDatum.DataBindings.Add("text", dsMyDataset, "tblCD.date")
    Me.CheckBoxActief.DataBindings.Add("text", dsMyDataset, "tblCD.active")
    Me.LabelNumber.Text = (Me.BindingContext(dsMyDataset).Position + 1).ToString & " of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
    End Sub

    Private Sub ButtonVolgend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVolgend.Click
    Me.BindingContext(dsMyDataset, "tblCD").Position = (Me.BindingContext(dsMyDataset, "tblCD").Position + 1)
    Me.LabelNumber.Text = (Me.BindingContext(dsMyDataset, "tblCD").Position + 1).ToString & " of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
    End Sub

    Private Sub ButtonVorig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVorig.Click
    Me.BindingContext(dsMyDataset, "tblCD").Position = Me.BindingContext(dsMyDataset, "tblCD").Position - 1
    Me.LabelNumber.Text = (Me.BindingContext(dsMyDataset, "tblCD").Position - 1).ToString & " of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
    End Sub


    Private Sub ButtonEinde_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEinde.Click
    Me.BindingContext(dsMyDataset, "tblCD").Position = Me.BindingContext(dsMyDataset, "tblCD").Count
    Me.LabelNumber.Text = (Me.BindingContext(dsMyDataset, "tblCD").Count).ToString & " of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
    End Sub

    Private Sub Buttonbegin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonbegin.Click
    Me.BindingContext(dsMyDataset, "tblCD").Position = 1
    Me.LabelNumber.Text = "1 of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
    End Sub
    End Class




    Thank you for your time.


    Tom

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Are you sure of what you are saying? Can you send a sample? Its very strange, maybe the textbox value is changed in other parts of the code.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    @ Lunatic

    Here you can find the requested files.

    Thanks

    Tom
    Attached Files Attached Files

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    @ lunatic

    and here the database.

    Tom
    Attached Files Attached Files

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I checked your program. You have some confusing problems:
    1- The dataset you are using 'DataSetZoeken12' already has a list of typed columns, one named "CDID" that is an autoincrement column, and then you are adding another tblCD.CDID untyped column to it. It binds to the Typed one that is actually "tblCD.CDID" and contaisn values of 0,1,2,3,... So thats why you are facing this problem.

    2- Even if you generate dataset with the OleDbDataAdapterzoeken1 still you will face problem, because you are changing the select text of dataadapter and different set of columns are chosen and then still trying to fill the previous dataset with it. In this manner you are trying to bind to an Untyped Dataset, that causes problem when you are for example binding a Text property to an Integer. So you may build an adapter with the command text of strSQLzoeken and generate a dataset with it, and then change the select command based on the selection. Remember in this manner you are not changing the column collection of the dataadapter, just applying some filters.
    Last edited by Lunatic3; Nov 18th, 2003 at 10:18 PM.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    @Lunatic,

    Thanks for taking the time to check my 'crappy' code. I know it needs some refreshments, but I'm a newbie so...

    BUt there are some things I don't understand:

    - Why has datasetzoeken12 some typed columns? Is this because I created the dataset with the wizard and because it is based on OleDBDataAdapterZOeken1?
    - Then you say I add some other columns to the datasetzoeken12, don't I use the same columns as when the dataset was created?
    - How would you solve this problem, could you please give me a code example? I don't understand your suggestion stated in your point 2.

    I hope you can help me, because I'm getting frustrated on this problem.

    Thanks Tom

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    No, you are not using the same columns, it looks like a different adapter filling the dataset.

    I added an adapter called oledbtest and a dataset called dstest to your project, and changed the button click code a little bit.
    Attached Files Attached Files
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    Thanks man,

    I'll look at your solution and give me response this evening.

    I appreciate what you are doing.

    Tom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width