pharaon's Profile User Rating: -----

Reputation: 0 Apprentice
Active Members
Active Posts:
80 (0.03 per day)
18-October 07
Profile Views:
Last Active:
User is offline Sep 04 2014 09:37 AM

Previous Fields

Who Cares
Dream Kudos:

Latest Visitors

Icon   pharaon has not set their status

Posts I've Made

  1. In Topic: many data with few textboxs

    Posted 29 Aug 2014

    View Postdemausdauth, on 28 August 2014 - 06:39 AM, said:

    Think about what you need the controls on your form to do.
    It seems like you want your button to have 2 responsibilities - initially load your data into your grid and also to add new data to the grid. What I would do is apply some SOLID principles and separate out the responsibility of what some methods do.

    For instance - maybe you should have a method to initially load the data to the grid, one for adding rows of data to the grid, one for saving data to the database, one for querying the database.

    Another thing to think about is this - you want to add a row to your datagridview, but in your code you don't actually seem to be doing anything that would add to your datagridview. If you are following the flow of - add the textbox data to bindingsource and then re query to fill the datagridview again, it doesn't seem to me to that the data in the binding source is being saved to the database. Granted I don't/haven't used the BindingSource myself so I don't know the subtleties of this control, but it doesn't appear that the textbox data is being persisted to the database.

    Last thought - sometimes you have to go back to square one. Get your code to do one thing at a time, add buttons to perform a specific function - load data, save textboxes to grid, save to database, etc... once you have these specific processes working, you can start to combine them (if necessary).

    I agree with you but at this stage I'm not trying to save to the database I'm just trying to bind controls to table then save that table at once to the database later
    so I'm using the DGV to check what data been saved to the table and I have trouble saving Date/Time to the table

    any one know how to bind Date/Time to table in the right way
  2. In Topic: many data with few textboxs

    Posted 21 Aug 2014

    I done this code so far
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            DataGridView1.DataSource = BindingSource1
        End Sub
        Private Sub BindControls()
            Dim adapter As New OleDb.OleDbDataAdapter("select Pname,Birthdate,Qualification,Job,Health,Religion,Tel from members", obj.con)
            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)
            adapter.InsertCommand = insert
            insert.Parameters.Add("@Pname", OleDbType.VarChar, 100, "Pname")
            insert.Parameters.Add("@Birthdate", OleDbType.DBDate, 10, "Birthdate")
            insert.Parameters.Add("@Qualification", OleDbType.VarChar, 100, "Qualification")
            insert.Parameters.Add("@Job", OleDbType.VarChar, 100, "Job")
            insert.Parameters.Add("@Health", OleDbType.VarChar, 100, "Health")
            insert.Parameters.Add("@Religion", OleDbType.VarChar, 100, "Religion")
            insert.Parameters.Add("@Tel", OleDbType.VarChar, 100, "Tel")
            adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
            Dim table As New DataTable
            adapter.FillSchema(table, SchemaType.Source)
            'table.Rows.Add(TextBox4.Text.Trim, DateTimePicker2.Value, TextBox6.Text.Trim, TextBox7.Text.Trim, TextBox8.Text.Trim, TextBox9.Text.Trim, CInt(TextBox10.Text))
            BindingSource1.DataSource = table
            TextBox4.DataBindings.Add("text", BindingSource1, "Pname")
            DateTimePicker2.DataBindings.Add("Value", BindingSource1, "Birthdate")
            TextBox6.DataBindings.Add("Text", BindingSource1, "Qualification")
            TextBox7.DataBindings.Add("text", BindingSource1, "Job")
            TextBox8.DataBindings.Add("text", BindingSource1, "Health")
            TextBox9.DataBindings.Add("text", BindingSource1, "Religion")
            TextBox10.DataBindings.Add("text", BindingSource1, "Tel")
        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?
  3. In Topic: many data with few textboxs

    Posted 21 Aug 2014

    any one have an idea for how to get this done
  4. In Topic: many data with few textboxs

    Posted 20 Aug 2014

  5. In Topic: many data with few textboxs

    Posted 16 Aug 2014

    dos that code make sense so far?
    Dim adapter As New OleDb.OleDbDataAdapter("select ID,Pname,Birthdate,Qualification,Job,Health,Religion,Tel from members", con)
    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)
    insert.Parameters.AddWithValue("@Pname", Form3.TextBox4.Text.Trim)
    insert.Parameters.AddWithValue("@Birthdate", Form3.DateTimePicker2)
    insert.Parameters.AddWithValue("@Qualification", Form3.TextBox6.Text.Trim)
    insert.Parameters.AddWithValue("@Job", Form3.TextBox7.Text.Trim)
    insert.Parameters.AddWithValue("@Health", Form3.TextBox8.Text.Trim)
    insert.Parameters.AddWithValue("@Religion", Form3.TextBox9.Text.Trim)
    insert.Parameters.AddWithValue("@Tel", Form3.TextBox10.Text.Trim)
    adapter.InsertCommand = insert
    Dim table As New DataTable
    adapter.FillSchema(table, SchemaType.Source)
    Form3.BindingSource1.DataSource = table
    Form3.TextBox4.DataBindings.Add(Form3.TextBox4.Text.Trim, Form3.BindingSource1, "Pname")
    Form3.DateTimePicker2.DataBindings.Add(Form3.DateTimePicker2.Value, Form3.BindingSource1, "Birthdate")
    Form3.TextBox6.DataBindings.Add(Form3.TextBox6.Text.Trim, Form3.BindingSource1, "Qualification")
    Form3.TextBox7.DataBindings.Add(Form3.TextBox7.Text.Trim, Form3.BindingSource1, "Job")
    Form3.TextBox8.DataBindings.Add(Form3.TextBox8.Text.Trim, Form3.BindingSource1, "Health")
    Form3.TextBox9.DataBindings.Add(Form3.TextBox9.Text.Trim, Form3.BindingSource1, "Religion")
    Form3.TextBox10.DataBindings.Add(Form3.TextBox10.Text.Trim, Form3.BindingSource1, "Tel")

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information




pharaon has no profile comments yet. Why not say hello?