解决方案 »

  1.   


      string connectionString = "server=(local);User ID=sa;Password=123;database=school;Connection Reset=FALSE";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                   
                    connection.Open();
                    using (SqlCommand cmd = new SqlCommand("Insert into dbo.class(id,name,pwd) values('" + s1+ "','" + s1 + "','" + s1 + "')", connection))
                    {
                        try
                        {  
                            cmd.ExecuteNonQuery();
                            Response.Write("<script>alert(\"已注册\")</Script>");
                        }
                        catch (Exception m)
                        { 
                            Response.Write("错误"+m); 
                        }
                        finally
                        {
                            cmd.Dispose();
                            connection.Close();
                        }
                    }
                }