Hi all
i have question again, this is my code:

private void btAdd_Click(object sender, EventArgs e)
        {
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            DataView dv;
            string sql = null;
            string connetionString = "Data Source=GOD_LOVE_ME;Initial Catalog=ProjetDB;Integrated Security=True";
            sql = "Select * from Material";
            SqlConnection connection = new SqlConnection(connetionString);

            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sql, connection);
                adapter.SelectCommand = command;
                adapter.Fill(ds, "Add New");
                adapter.Dispose();
                command.Dispose();
                connection.Close();

                dv = new DataView(ds.Tables[0]);
                DataRowView newRow = dv.AddNew();
                newRow["MaterialID"] = txKode.Text;
                newRow["MaterialName"] = txNama.Text;
                newRow["MatGroupID"] = cbGroup.Text;
                newRow.EndEdit();
                dv.Sort = "MaterialID";


                DG1.DataSource = dv;

            }
            catch (Exception ex)
            {
                MessageBox.Show (ex.ToString());
            }

this code for add row but my problem is how making row in last table, because my code only add in second row.

best regards,
martin

Recommended Answers

All 2 Replies

Your question is bit unclear to me. I think you want to add a record into the database along with datatable. Isn't it?

right, and i want new record row at the bottom datagrid

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.