Dim sqlconn As New SqlConnection("sqlconnectionstring") Dim da As New SqlDataAdapter(String.Empty, sqlconn) Dim sql As New StringBuilder("insert into [") sql.Append(Form1.TreeView1.SelectedNode.Text.Replace("]", "\]")) sql.Append("] ([Id], ") Dim sbOn As New StringBuilder(") values(@Id, ") Dim andRequired As Boolean = False If Not String.IsNullOrEmpty(IDTextBox.Text) Then da.SelectCommand.Parameters.AddWithValue("@Id", Form1.DataGridView1.Rows.Count + 1) End If If Not String.IsNullOrEmpty(First_NameTextBox.Text) Then If andRequired Then sql.Append(", ") sbOn.Append(", ") End If sql.Append("[First_name]") sbOn.Append("@Firstname") da.SelectCommand.Parameters.AddWithValue("@Firstname", First_NameTextBox.Text) andRequired = True End If sql.AppendFormat(sbOn.ToString + ")") da.SelectCommand.CommandText = sql.ToString() Dim dt As New DataTable da.Fill(dt) DataGridView1.DataSource = dt
DataGridView1.DataSource
Nothing
DataGridView.Rows.Clear()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)