The best way to insert such kind of data is to use datatable that hold all the record at a time and commit into the database at once.I am assuming the database table name is
Registration
.
public void InsertRegistration()
{
DataTable registration = new DataTable("Registration");
using (SqlConnection connection = new SqlConnection("connectionString"))
{
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand selectCommand = new SqlCommand("SELECT TOP 1 valid_reg FROM Registration", connection);
adapter.SelectCommand = selectCommand;
adapter.Fill(registration);
foreach (string line in richTextBox1.Lines)
{
DataRow newRegistration = registration.NewRow();
newRegistration["valid_reg"] = line;
registration.Rows.Add(newRegistration);
}
SqlCommand insertCommand = new SqlCommand("INSERT INTO Registration(valid_reg) VALUES(@valid_reg)", connection);
SqlParameter parameter = new SqlParameter("@valid_reg", SqlDbType.NVarChar);
insertCommand.Parameters.Add(parameter);
adapter.InsertCommand = insertCommand;
adapter.Update(registration);
}
}
I hope this helps you well.