Results 1 to 28 of 28

Thread: [RESOLVED] many data with few textboxs

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Resolved [RESOLVED] many data with few textboxs

    I want to save the data of 5 members of one family into database
    like husband, wife, child1, 2, 3
    with this data
    name, age, job, phone, birthdate

    but I want to make only 5 textbox for each filed for all the members
    not 5 textbox for each filed for each member 5 x 5 = 25

    and save all that one time into database is there away to do that

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    Are you saying that you want to enter the data for one person at a time into the TextBoxes or that you want to enter all the data for all the people at the same time? If it's the former then I can certainly suggest how to do that but, if it's the latter, I would recommend against using TextBoxes and use a DataGridView instead.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    I want to enter the data for one person at a time but save all the data of each person all at once

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    So then, you should start by creating a DataTable with the appropriate schema. You can build that schema yourself or you can call FileSchema on an appropriate data adapter, which will be the same data adapter that you use to save the data. You can then bind that DataTable to a BindingSource and bind that to your controls. Each time you want to add a new record you call AddNew on the BindingSource. I think that you'll need to call EndEdit to commit the previous record first and you'll definitely need to do so before saving the data to the database. You save the data by calling Update on the data adapter.

    You can follow the CodeBank link in my signature below and check out my thread on Retrieving & Saving Data to get examples of how to do the data access part. The data-binding will look something like this:
    Code:
    myBindingSource.DataSource = myDataTable
    myTextBox.DataBindings.Add("Text", myBindingSource, "ColumnName")

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    ok what I done so far is this
    vb Code:
    1. Dim adapter As New OleDb.OleDbDataAdapter("select Pname,Birthdate,Qualification,Job,Health,Tel from members", con)
    2.         Dim insert As New OleDb.OleDbCommand("INSERT INTO members (Pname,Birthdate,Qualification,Job,Health,Tel) VALUES (@Pname,@Birthdate,@Qualification,@Job,@Health,@Tel)", con)
    3.         insert.Parameters.AddWithValue("@Pname", Form3.TextBox4.Text.Trim)
    4.         insert.Parameters.AddWithValue("@Birthdate", Form3.DateTimePicker2)
    5.         insert.Parameters.AddWithValue("@Qualification", Form3.TextBox6.Text.Trim)
    6.         insert.Parameters.AddWithValue("@Job", Form3.TextBox7.Text.Trim)
    7.         insert.Parameters.AddWithValue("@Health", Form3.TextBox8.Text.Trim)
    8.         insert.Parameters.AddWithValue("@Tel", Form3.TextBox10.Text.Trim)
    9.  
    10.         adapter.InsertCommand = insert
    11.         Dim table As New DataTable
    12.         adapter.FillSchema(table, SchemaType.Source)
    13.         adapter.Update(table)

    but how to do the binding for the datatable and the BindingSource also how can I insert that data for all the members into that table before I save it all at once to the database

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    It feels like you read part of my post and ignored the rest.
    Quote Originally Posted by new1 View Post
    how to do the binding for the datatable and the BindingSource
    Like I showed you in my previous post:
    Quote Originally Posted by jmcilhinney View Post
    The data-binding will look something like this:
    Code:
    myBindingSource.DataSource = myDataTable
    myTextBox.DataBindings.Add("Text", myBindingSource, "ColumnName")
    Quote Originally Posted by new1 View Post
    how can I insert that data for all the members into that table before I save it all at once to the database
    Like I told you in my previous post:
    Quote Originally Posted by jmcilhinney View Post
    Each time you want to add a new record you call AddNew on the BindingSource. I think that you'll need to call EndEdit to commit the previous record first and you'll definitely need to do so before saving the data to the database.
    Calling AddNew creates a new row and calling EndEdit adds it to the DataTable. If you call AddNew twice without calling EndEdit in between, I'm not sure whether the first row gets added to the DataTable automatically or discarded. You can test that easily enough for yourself. You definitely have to call EndEdit before saving or else the last row you created will not be added. The new row created by calling AddNew will automatically become the current row so it's fields will be automatically bound to the controls. You call AddNew, the user enters the field values and then you commit the row.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    dos that code make sense so far?
    vb.net Code:
    1. Dim adapter As New OleDb.OleDbDataAdapter("select ID,Pname,Birthdate,Qualification,Job,Health,Religion,Tel from members", con)
    2.         Dim insert As New OleDb.OleDbCommand("INSERT INTO members (ID,Pname,Birthdate,Qualification,Job,Health,Religion,Tel) VALUES (@ID,@Pname,@Birthdate,@Qualification,@Job,@Health,@Religion,@Tel)", con)
    3.         insert.Parameters.AddWithValue("@Pname", Form3.TextBox4.Text.Trim)
    4.         insert.Parameters.AddWithValue("@Birthdate", Form3.DateTimePicker2)
    5.         insert.Parameters.AddWithValue("@Qualification", Form3.TextBox6.Text.Trim)
    6.         insert.Parameters.AddWithValue("@Job", Form3.TextBox7.Text.Trim)
    7.         insert.Parameters.AddWithValue("@Health", Form3.TextBox8.Text.Trim)
    8.         insert.Parameters.AddWithValue("@Religion", Form3.TextBox9.Text.Trim)
    9.         insert.Parameters.AddWithValue("@Tel", Form3.TextBox10.Text.Trim)
    10.         adapter.InsertCommand = insert
    11.  
    12.         Dim table As New DataTable
    13.         adapter.FillSchema(table, SchemaType.Source)
    14.         Form3.BindingSource1.DataSource = table
    15.  
    16.         Form3.TextBox4.DataBindings.Add(Form3.TextBox4.Text.Trim, Form3.BindingSource1, "Pname")
    17.         Form3.DateTimePicker2.DataBindings.Add(Form3.DateTimePicker2.Value, Form3.BindingSource1, "Birthdate")
    18.         Form3.TextBox6.DataBindings.Add(Form3.TextBox6.Text.Trim, Form3.BindingSource1, "Qualification")
    19.         Form3.TextBox7.DataBindings.Add(Form3.TextBox7.Text.Trim, Form3.BindingSource1, "Job")
    20.         Form3.TextBox8.DataBindings.Add(Form3.TextBox8.Text.Trim, Form3.BindingSource1, "Health")
    21.         Form3.TextBox9.DataBindings.Add(Form3.TextBox9.Text.Trim, Form3.BindingSource1, "Religion")
    22.         Form3.TextBox10.DataBindings.Add(Form3.TextBox10.Text.Trim, Form3.BindingSource1, "Tel")
    23.  
    24.         adapter.Update(table)

    if not tell me what to modify

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    Firstly, you can't be calling FillSchema and Update in the same method. When is the user going to enter the data? You need to create the DataTable and bind it to your controls to begin with. The user is then going to enter the data, thus populating the DataTable. Finally, you'll save the data.

    Secondly, you can't use AddWithValue to create the parameters. You're going to be inserting multiple records from the DataTable so that's where the data has to come from for the parameters.

    Finally, where exactly is that code? If it's in Form3 then you should be using Me rather than Form3. If it's not in Form3 then you shouldn't be doing the binding there at all. Creating the DataTable and saving the data elsewhere is fine but in that case you should be passing the DataTable in to Form3 and then Form3 does its own binding.

    For the first two points particularly, follow the CodeBank link in my signature below and check out my thread on Retrieving & Saving Data. It includes two examples of using a data adapter to save data; one that uses a data adapter and one that doesn't. That will show you how to separate the creating of the DataTable and the saving of the data. They use Fill but you can replace that with FillSchema. Note that you also need to provide for the user creating a new row in the DataTable. I don't see any calls to AddNew or EndEdit in there.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    Secondly, you can't use AddWithValue to create the parameters. You're going to be inserting multiple records from the DataTable so that's where the data has to come from for the parameters.
    so what to use


    vb Code:
    1. Dim adapter As New OleDb.OleDbDataAdapter("select Pname,Birthdate,Qualification,Job,Health,Religion,Tel from members", obj.con)
    2.         Dim insert As New OleDb.OleDbCommand("INSERT INTO members (Pname,Birthdate,Qualification,Job,Health,Religion,Tel) VALUES (@ID,@Pname,@Birthdate,@Qualification,@Job,@Health,@Religion,@Tel)", obj.con)
    3.         adapter.InsertCommand = insert
    4.         insert.Parameters.Add("@Pname", OleDbType.VarChar, 100, "Pname")
    5.         insert.Parameters.Add("@Birthdate", OleDbType.DBDate, 10, "Birthdate")
    6.         insert.Parameters.Add("@Qualification", OleDbType.VarChar, 100, "Qualification")
    7.         insert.Parameters.Add("@Job", OleDbType.VarChar, 100, "Job")
    8.         insert.Parameters.Add("@Health", OleDbType.VarChar, 100, "Health")
    9.         insert.Parameters.Add("@Religion", OleDbType.VarChar, 100, "Religion")
    10.         insert.Parameters.Add("@Tel", OleDbType.VarChar, 100, "Religion")
    11.         adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
    12.  
    13.         Dim table As New DataTable
    14.         table.Columns.Add("Pname", GetType(String))
    15.         table.Columns.Add("Birthdate", GetType(DateAndTime))
    16.         table.Columns.Add("Qualification", GetType(String))
    17.         table.Columns.Add("Job", GetType(String))
    18.         table.Columns.Add("Health", GetType(String))
    19.         table.Columns.Add("Religion", GetType(String))
    20.         table.Columns.Add("Tel", GetType(Integer))
    21.  
    22.         adapter.FillSchema(table, SchemaType.Source)
    23.  
    24.         BindingSource1.DataSource = table
    25.         TextBox4.DataBindings.Add(TextBox4.Text.Trim, BindingSource1, "Pname")
    26.         DateTimePicker2.DataBindings.Add(DateTimePicker2.Value, BindingSource1, "Birthdate")
    27.         TextBox6.DataBindings.Add(TextBox6.Text.Trim, BindingSource1, "Qualification")
    28.         TextBox7.DataBindings.Add(TextBox7.Text.Trim, BindingSource1, "Job")
    29.         TextBox8.DataBindings.Add(TextBox8.Text.Trim, BindingSource1, "Health")
    30.         TextBox9.DataBindings.Add(TextBox9.Text.Trim, BindingSource1, "Religion")
    31.         TextBox10.DataBindings.Add(TextBox10.Text.Trim, BindingSource1, "Tel")
    32.  
    33.         adapter.Update(table)

    that's what I did so far but I don't know how to add new row with bindingsource since every row will continue the person name, birthday, Qualification, job, health, Religion, tel

    can you show me how to do that with th ebindingsource

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    Your parameters look better now. You can only use AddWithValue if you want to add the parameter with a specific value. You obviously don't because you don't have any values at that point and each parameter is going to have multiple values because you want to insert multiple rows. You have to use Add to create the parameter and to tell it where in the DataTable to get the data from for each row that's inserted, as you have now done.

    To balance that improvement in your code, you've also made it worse in another way. Why are you adding columns to your DataTable manually and then calling FillSchema?

    Next, your bindings are an issue. Have you read the documentation to see what the parameters of the DataBindings.Add method mean? Your first parameter is very wrong.

    Also, you're still calling Update in the same method that creates the DataTable. As I have already stated, those must be separated. Update is what saves the data to the database so calling it before you've actually added any data to the DataTable is obviously of no value. Step 1 is creating and binding the DataTable, step 2 is adding the data and step three is saving the data. You can't do step 1 and step 3 in a single method.

    Finally, I've already told you several times that you add a new row by calling AddNew on the BindingSource. That will only help, of course, if the BindingSource is bound correctly.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    is the code right so far?
    vb.net Code:
    1. Dim adapter As New OleDb.OleDbDataAdapter("select Pname,Birthdate,Qualification,Job,Health,Religion,Tel from members", obj.con)
    2.         Dim insert As New OleDb.OleDbCommand("INSERT INTO members (Pname,Birthdate,Qualification,Job,Health,Religion,Tel) VALUES (@ID,@Pname,@Birthdate,@Qualification,@Job,@Health,@Religion,@Tel)", obj.con)
    3.         adapter.InsertCommand = insert
    4.         insert.Parameters.Add("@Pname", OleDbType.VarChar, 100, "Pname")
    5.         insert.Parameters.Add("@Birthdate", OleDbType.DBDate, 10, "Birthdate")
    6.         insert.Parameters.Add("@Qualification", OleDbType.VarChar, 100, "Qualification")
    7.         insert.Parameters.Add("@Job", OleDbType.VarChar, 100, "Job")
    8.         insert.Parameters.Add("@Health", OleDbType.VarChar, 100, "Health")
    9.         insert.Parameters.Add("@Religion", OleDbType.VarChar, 100, "Religion")
    10.         insert.Parameters.Add("@Tel", OleDbType.VarChar, 100, "Religion")
    11.         adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
    12.  
    13.         Dim table As New DataTable
    14.         adapter.FillSchema(table, SchemaType.Source)
    15.         BindingSource1.DataSource = table
    16.  
    17.         TextBox4.DataBindings.Add(TextBox4.Text.Trim, BindingSource1, "Pname")
    18.         DateTimePicker2.DataBindings.Add(DateTimePicker2.Value, BindingSource1, "Birthdate")
    19.         TextBox6.DataBindings.Add(TextBox6.Text.Trim, BindingSource1, "Qualification")
    20.         TextBox7.DataBindings.Add(TextBox7.Text.Trim, BindingSource1, "Job")
    21.         TextBox8.DataBindings.Add(TextBox8.Text.Trim, BindingSource1, "Health")
    22.         TextBox9.DataBindings.Add(TextBox9.Text.Trim, BindingSource1, "Religion")
    23.         TextBox10.DataBindings.Add(TextBox10.Text.Trim, BindingSource1, "Tel")

    you said
    Next, your bindings are an issue. Have you read the documentation to see what the parameters of the DataBindings.Add method mean? Your first parameter is very wrong.
    but you mentioned before that DataBindings.Add is to add new column so how can it be wrong

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    Quote Originally Posted by new1 View Post
    is the code right so far?
    vb.net Code:
    1. Dim adapter As New OleDb.OleDbDataAdapter("select Pname,Birthdate,Qualification,Job,Health,Religion,Tel from members", obj.con)
    2.         Dim insert As New OleDb.OleDbCommand("INSERT INTO members (Pname,Birthdate,Qualification,Job,Health,Religion,Tel) VALUES (@ID,@Pname,@Birthdate,@Qualification,@Job,@Health,@Religion,@Tel)", obj.con)
    3.         adapter.InsertCommand = insert
    4.         insert.Parameters.Add("@Pname", OleDbType.VarChar, 100, "Pname")
    5.         insert.Parameters.Add("@Birthdate", OleDbType.DBDate, 10, "Birthdate")
    6.         insert.Parameters.Add("@Qualification", OleDbType.VarChar, 100, "Qualification")
    7.         insert.Parameters.Add("@Job", OleDbType.VarChar, 100, "Job")
    8.         insert.Parameters.Add("@Health", OleDbType.VarChar, 100, "Health")
    9.         insert.Parameters.Add("@Religion", OleDbType.VarChar, 100, "Religion")
    10.         insert.Parameters.Add("@Tel", OleDbType.VarChar, 100, "Religion")
    11.         adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
    12.  
    13.         Dim table As New DataTable
    14.         adapter.FillSchema(table, SchemaType.Source)
    15.         BindingSource1.DataSource = table
    That part is correct, up to the data bindings.
    Quote Originally Posted by new1 View Post
    you mentioned before that DataBindings.Add is to add new column so how can it be wrong
    I never mentioned that because it's not the case. The DataBindings.Add method is to add a Binding, which binds a column/property of the data source to a property of the control. As I said, your first parameter is wrong. Again I ask, have you read the documentation for that method? If not, why not? If you have then you should know what that first parameter is for and why it's wrong.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    no I didn't read documentation for that method yet..hope you can provide me with a link for that method

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    Quote Originally Posted by new1 View Post
    no I didn't read documentation for that method yet..hope you can provide me with a link for that method
    What's wrong with your VS Help menu?

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    how about the code now?

    vb.net Code:
    1. Dim adapter As New OleDb.OleDbDataAdapter("select Pname,Birthdate,Qualification,Job,Health,Religion,Tel from members", obj.con)
    2.         Dim insert As New OleDb.OleDbCommand("INSERT INTO members (Pname,Birthdate,Qualification,Job,Health,Religion,Tel) VALUES (@ID,@Pname,@Birthdate,@Qualification,@Job,@Health,@Religion,@Tel)", obj.con)
    3.         adapter.InsertCommand = insert
    4.         insert.Parameters.Add("@Pname", OleDbType.VarChar, 100, "Pname")
    5.         insert.Parameters.Add("@Birthdate", OleDbType.DBDate, 10, "Birthdate")
    6.         insert.Parameters.Add("@Qualification", OleDbType.VarChar, 100, "Qualification")
    7.         insert.Parameters.Add("@Job", OleDbType.VarChar, 100, "Job")
    8.         insert.Parameters.Add("@Health", OleDbType.VarChar, 100, "Health")
    9.         insert.Parameters.Add("@Religion", OleDbType.VarChar, 100, "Religion")
    10.         insert.Parameters.Add("@Tel", OleDbType.VarChar, 100, "Religion")
    11.         adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
    12.  
    13.         Dim table As New DataTable
    14.         adapter.FillSchema(table, SchemaType.Source)
    15.         BindingSource1.DataSource = table
    16.  
    17.         TextBox4.DataBindings.Add("text", BindingSource1, "Pname")
    18.         DateTimePicker2.DataBindings.Add("Value", BindingSource1, "Birthdate")
    19.         TextBox6.DataBindings.Add("Text", BindingSource1, "Qualification")
    20.         TextBox7.DataBindings.Add("text", BindingSource1, "Job")
    21.         TextBox8.DataBindings.Add("text", BindingSource1, "Health")
    22.         TextBox9.DataBindings.Add("text", BindingSource1, "Religion")
    23.         TextBox10.DataBindings.Add("text", BindingSource1, "Tel")

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    That looks pretty good for the first part, i.e. creating the DataTable and binding it. Just note that you're going to have to use the data adapter again later to save the data, so you'll have to assign it to a member variable rather than a local variable.

    Now, as I've said previously, you'll need to call AddNew on the BindingSource each time you want to add a new row. That will most likely be done in the Click event of a Button as the user will have to initiate it because only they know when they're done with the previous record. As I have also said, I'm not sure whether calling AddNew commits the previous edit or discards it, so you'll have to conform that. It's easy enough to work out because if you call AddNew a few times and end up with no rows in your DataTable then obviously nothing has been committed. In that case, you'll need an explicit call to the EndEdit method of the BindingSource before each call to AddNew.

    Finally, as I have also already said, you'll need to call EndEdit to commit the last row and then Update on the data adapter to save the data. That will again most likely be done in a Button's Click event handler because only the user knows when they are ready to save the data.

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    ok here's the code
    vb.net Code:
    1. Dim adapter As New OleDb.OleDbDataAdapter("select Pname,Birthdate,Qualification,Job,Health,Religion,Tel from members", obj.con)
    2.         Dim insert As New OleDb.OleDbCommand("INSERT INTO members (Pname,Birthdate,Qualification,Job,Health,Religion,Tel) VALUES (@ID,@Pname,@Birthdate,@Qualification,@Job,@Health,@Religion,@Tel)", obj.con)
    3.         adapter.InsertCommand = insert
    4.         insert.Parameters.Add("@Pname", OleDbType.VarChar, 100, "Pname")
    5.         insert.Parameters.Add("@Birthdate", OleDbType.DBDate, 10, "Birthdate")
    6.         insert.Parameters.Add("@Qualification", OleDbType.VarChar, 100, "Qualification")
    7.         insert.Parameters.Add("@Job", OleDbType.VarChar, 100, "Job")
    8.         insert.Parameters.Add("@Health", OleDbType.VarChar, 100, "Health")
    9.         insert.Parameters.Add("@Religion", OleDbType.VarChar, 100, "Religion")
    10.         insert.Parameters.Add("@Tel", OleDbType.VarChar, 100, "Religion")
    11.         adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
    12.  
    13.         Dim table As New DataTable
    14.         adapter.FillSchema(table, SchemaType.Source)
    15.         BindingSource1.DataSource = table
    16.  
    17.         TextBox4.DataBindings.Add("text", BindingSource1, "Pname")
    18.         DateTimePicker2.DataBindings.Add("Value", BindingSource1, "Birthdate")
    19.         TextBox6.DataBindings.Add("Text", BindingSource1, "Qualification")
    20.         TextBox7.DataBindings.Add("text", BindingSource1, "Job")
    21.         TextBox8.DataBindings.Add("text", BindingSource1, "Health")
    22.         TextBox9.DataBindings.Add("text", BindingSource1, "Religion")
    23.         TextBox10.DataBindings.Add("text", BindingSource1, "Tel")

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         BindControls()
    3.         BindingSource1.AddNew()
    4.         BindingSource1.EndEdit()
    5.         DataGridView1.DataSource = BindingSource1
    6.     End Sub

    but the DGV only show empty row when I fill the textboxes with data and click the button the DGV show empty row why?

  18. #18
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: many data with few textboxs

    but the DGV only show empty row when I fill the textboxes with data and click the button the DGV show empty row why?
    Make sure that the BindingSource.DataSource has records and that your DataGridView control has columns.
    MSDN DataGridView.AutoGenerateColumns Property

    KGC
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    any one have an idea for how to get this done

  20. #20
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    Your second code snippet in post #17 doesn't really make sense. You call a method named "BindControls" and then a couple of lines later you bind a DataGridView. Why isn't that grid being bound with the other controls? What is Button1 actually for? Just like everything else in that code, it has a meaningless name. Is it being clicked once or every time the user adds a new row? If it's the latter then why would you be binding controls every time? Why are you calling EndEdit immediately after AddNew? How many times can I say the same thing and it be ignored?
    you'll need an explicit call to the EndEdit method of the BindingSource before each call to AddNew.
    Why is this the first we're hearing of a DataGridView too? What's the deal here - are you expecting the user to enter the field values in the TextBoxes and then they appear in the grid? That's probably information that should have been provided before now.

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    well what I do is fill the textboxs with the data then call BindControls() to fill the table with those data so I made the DGV to see if the data is stored in the table or not and it just show me empty rows which mean no data from the textboxes have been saved to the table

    the DGV is just for the test as well as the button and I click it once to save the data from the textboxs to the table but it didn't work

    and I don't understand what you quite mean by that
    you'll need an explicit call to the EndEdit method of the BindingSource before each call to AddNew.
    isn't that what I did by calling BindingSource1.EndEdit()

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    ok I fix the code it work fine now although there's one last thing
    vb.net Code:
    1. DateTimePicker2.DataBindings.Add("Value", BindingSource1, "Birthdate")
    it doesn't add new record because of that line
    but when I change it to
    vb.net Code:
    1. DateTimePicker2.DataBindings.Add("text", BindingSource1, "Birthdate")
    it work fine..
    so will that effect on saving it to the DB since it's Date & time Data type in the DB table
    and there away to fix that

  23. #23
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    Quote Originally Posted by new1 View Post
    I don't understand what you quite mean by that


    isn't that what I did by calling BindingSource1.EndEdit()
    Do you not understand the difference between "before" and "after"? I said, over and over, to call EndEdit before calling AddNew. You're calling EndEdit after calling AddNew. That's a fairly fundamental difference. Calling EndEdit ends the current edit. The point of it is to end the editing of the previous row before adding a new one. You're ending the edit immediately after adding a row, so the row is obviously going to be empty.

  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    ok I fix the code it work fine now although there's one last thing
    vb.net Code:
    1. DateTimePicker2.DataBindings.Add("Value", BindingSource1, "Birthdate")
    it doesn't add new record because of that line
    but when I change it to
    vb.net Code:
    1. DateTimePicker2.DataBindings.Add("text", BindingSource1, "Birthdate")
    it work fine..
    so will that effect on saving it to the DB since it's Date & time Data type in the DB table
    and there away to fix that

  25. #25
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: many data with few textboxs

    What data type is that Birthdate column?

  26. #26

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    it's Date/Time in the database, but I'm not saving it yet
    it just doesn't add those data to the bindingsource or to the table
    vb.net Code:
    1. DateTimePicker2.DataBindings.Add("Value", BindingSource1, "Birthdate")
    2.  
    3. 19.        TextBox6.DataBindings.Add("Text", BindingSource1, "Qualification")
    4.  
    5. 20.        TextBox7.DataBindings.Add("text", BindingSource1, "Job")
    6.  
    7. 21.        TextBox8.DataBindings.Add("text", BindingSource1, "Health")
    8.  
    9. 22.        TextBox9.DataBindings.Add("text", BindingSource1, "Religion")
    10.  
    11. 23.        TextBox10.DataBindings.Add("text", BindingSource1, "Tel")
    unless I change it from value to text

  27. #27
    Registered User
    Join Date
    Aug 2014
    Posts
    3

    Re: many data with few textboxs

    you will be needing only 5 text boxes for name, age, job, birthdate only. then add all the members to textboxes one-by-one.

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: many data with few textboxs

    Quote Originally Posted by vprog View Post
    you will be needing only 5 text boxes for name, age, job, birthdate only. then add all the members to textboxes one-by-one.
    that's is what I'm trying to do

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