数据库插入数据时会插入两条相同的数据
SqlConnectionconn=newSqlConnection();conn.ConnectionString="UserID=sa;InitialCatalog=...
SqlConnection conn = new SqlConnection(); conn.ConnectionString = "User ID=sa;Initial Catalog=User;Data Source= (local);Password=123456"; if (conn.State == ConnectionState.Closed) { conn.Open(); } SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into Table_1 ( Uname, Pass,Mark ,Sex,Tel,Address,Email) values('" + name + "','" + pass + "','普通用户','" + sex + "','" + tel + "','" + address + "','" + emial + "')"; int n = cmd.ExecuteNonQuery(); //判断返回的参数是否大于0,如果大于说明登录成功 if (n>0) { SqlDataReader read = cmd.ExecuteReader(); HttpCookie cookie = new HttpCookie("Name"); Request.Cookies.Clear(); cookie.Value = TextBox1.Text; cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); read.Close(); Page.Response.Redirect("~/user-index.aspx");
} else { RegisterStartupScript("", "<script>alert('注册失败!')</script>"); } conn.Close(); 展开
} else { RegisterStartupScript("", "<script>alert('注册失败!')</script>"); } conn.Close(); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询