Results 1 to 8 of 8

Thread: datagrid pass to database

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    datagrid pass to database

    i want to pass the value of the textboxes first in datagrid then save it to the database...

    e.g.
    text1.text = value1
    text2.text = value2


    how would i do that?

    ask if its not clear... tnx
    *****************
    VB6,PHP,VS 2005

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: datagrid pass to database

    Code:
    this.dataGridView1.Rows[0].Cells[0].Value = this.textBox1.Text;
    As far as saving to the database, these will help you get started:
    http://msdn2.microsoft.com/en-us/lib...97(VS.80).aspx
    (in VB but very good) http://vbforums.com/showthread.php?t=469872

    Good luck.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: datagrid pass to database

    i tried above but it has error like below,
    "Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index"

    sorry i'm not familiar could you please give me more examples?

    tnx
    *****************
    VB6,PHP,VS 2005

  4. #4
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: datagrid pass to database

    The example above refers to the first cell in the first row of the DataGridView. It seems you do not have any cells in your DataGridView?

    Can you also confirm that you are using a DataGridView and not a DataGrid?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: datagrid pass to database

    i am using datagridview, all inputed in the 2 textboxes after the button clicked
    the text in the 2text boxes will send to the datagridview

    text1.text= sample1
    text2.text= sample2

    column1 column2
    sample1 sample2
    *****************
    VB6,PHP,VS 2005

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: datagrid pass to database

    i am using datagridview, all inputed in the 2 textboxes after the button clicked
    the text in the 2text boxes will send to the datagridview

    text1.text= sample1
    text2.text= sample2

    datagridview:
    column1 column2
    sample1 sample2

    and how would i get all data in the datagridview?
    *****************
    VB6,PHP,VS 2005

  7. #7
    Registered User RaviIntegra's Avatar
    Join Date
    Mar 2007
    Location
    Pondicherry, India
    Posts
    125

    Re: datagrid pass to database

    vb Code:
    1. DataGridView1.Rows(0).Cells(0).Value=text1.text
    2. DataGridView1.Rows(1).Cells(0).Value=text2.text

    This will work fine

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: datagrid pass to database

    Code:
       private void button1_Click(object sender, EventArgs e)
            {
                string[] DataResult1 = { textBox1.Text, textBox2.Text};
                dataGridView1.Rows.Add(DataResult1);
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                dataGridView1.Columns.Add("colName", "Name");
                dataGridView1.Columns.Add("colSurName", "Last Name");
            }
    above code will send to the datagridview all inputed data?
    but how can i get all data in the datagrid now?
    *****************
    VB6,PHP,VS 2005

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