User1400794712 posted
Hi scottdg,
On button click I need to create a new row for each of the three additional textboxes if they have a value.
Are you confused of this? If so, we can add multiple to Database like this:
protected void Button1_Click(object sender, EventArgs e)
{
string queryString =
"INSERT Months(month,year) "
+ "VALUES(@month,2018);";
string connectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
if (!String.IsNullOrEmpty(TextBox1.Text))
{
SqlCommand command = new SqlCommand(queryString, conn);
command.Parameters.AddWithValue("@month", TextBox1.Text);
command.ExecuteNonQuery();
}
if (!String.IsNullOrEmpty(TextBox2.Text))
{
SqlCommand command = new SqlCommand(queryString, conn);
command.Parameters.AddWithValue("@month", TextBox2.Text);
command.ExecuteNonQuery();
}
if (!String.IsNullOrEmpty(TextBox3.Text))
{
SqlCommand command = new SqlCommand(queryString, conn);
command.Parameters.AddWithValue("@month", TextBox3.Text);
command.ExecuteNonQuery();
}
conn.Close();
}
}
If you're confused by other things, please feel free to post back and explain your problem in detail.
Best Regards,
Daisy