您好,每当我按下刷新按钮时,我都会遇到问题,它会不断添加:/我该如何防止它?这是我第 2 天想出来的,但我失败了:(
protected void Button1_Click(object sender, EventArgs e)
{
//Instantiate the connection with the database
using (SqlConnection myConnection = new SqlConnection("user id=username;" +
"password=password;" +
"trusted_connection=yes;" +
"database=DataBaseConnection;" +
"connection timeout=30;"))
{
//Open the Connection object
myConnection.Open();
//Instantiate a SQL Command with an INSERT query
SqlCommand myCommand = new SqlCommand("INSERT INTO BasicInfo (Firstname,Surname) Values(@a,@b);", myConnection);
if (TextBox1.Text !=null && TextBox2.Text != null)
{
//Texbox
myCommand.Parameters.AddWithValue("@a", TextBox1.Text);
myCommand.Parameters.AddWithValue("@b", TextBox2.Text);
//Execute the query
myCommand.ExecuteNonQuery();
}
else
{
//Code HEre?
}