3

What i try here is, i want to Add 4 textbox to datagridview from dataset. Here is what i do,

i create a dataset and set some column with it, and then i bind the "dataset" to BindingSource which is i named them

dataset = ds1 BindingSource = bs1

then i select the datasource in datagridview with "bs1", then the column showed up, then i change the column header name. Here come my problem, i try bind 4 textbox entry to datagridview like this

    public void AddRow()
    {
        try
        {
            DataRow dr1 = dt1.NewRow();

            dr1["cnNo"] = dgv_details.Rows.Count + 1;
            dr1["cnProductID"] = txt_ProductID.Text;
            dr1["cnProductName"] = txt_ProductName.Text;
            dr1["cnQty"] = txt_Qty.Text;
            dr1["cnPrice"] = txt_Price.Text;

            dt1.Rows.Add();

            MessageBox.Show("Executed");

        }
        catch (Exception)
        {
            MessageBox.Show("Duplicate entry");
        }
    }

i should work, the row is added new, but all of the row is blank, no entry is added to datagridview, what i got is new row with blank row, what i missed here?

*cnNo here mean "cn" is column name, this is how i named them in dataset column

1 Answer 1

2

You need to add the row:

dt1.Rows.Add(dr1);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.