0

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

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by botaxsmaniz
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.