Results 1 to 10 of 10

Thread: how to insert values into datagrid

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    103

    how to insert values into datagrid

    how to insert values into datagrid, please help me with sample code

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

    Re: how to insert values into datagrid

    You're going to have to provide a much more complete explanation of what you're doing than that. We could guess, but if we guess wrong then you've wasted our time and yours. Please always provide a full and clear description of the problem.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    103

    Re: how to insert values into datagrid

    have 10 textbox , 1 datgrid, 1 button control in my form,

    after entering values in my all textbox i need to insert that values in my datagrid though button click event

    please give me sample code for this

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

    Re: how to insert values into datagrid

    Does the grid contain data already? Where did the data come from? If you're adding data to a database then it would make most sense to use a DataTable bound to both the grid and the TextBoxes.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    103

    Re: how to insert values into datagrid

    data grid does not have value already, after giving input in all textbox in need to insert that all values in datagrid

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

    Re: how to insert values into datagrid

    So, the data is NOT going to be saved to a database?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    103

    Re: how to insert values into datagrid

    yes you are correct.

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

    Re: how to insert values into datagrid

    In that case, you can do something like this:
    vb.net Code:
    1. myDataGridView.Rows.Add(New Object() {Me.TextBox1.Text, Me.TextBox2.Text, Me.TextBox3.Text})
    Obviously you need to specify the correct number of TextBoxes in the correct order for the columns in your grid.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    103

    Re: how to insert values into datagrid

    i am getting error as

    No row can be added to a DataGridView control that does not have columns. Columns must be added first.

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

    Re: how to insert values into datagrid

    I would hope that that error message would speak for itself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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