错误信息如下:
“/”应用程序中的服务器错误。HTTP 错误 400 - Bad Request。版本信息: ASP.NET Development Server 10.0.0.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;namespace WebHms
{
    public partial class Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {        }        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection myConn = new SqlConnection("server=localhost\\SQLEXPRESS;database=HMS;uid=sa;pwd=123");
            string insertPatient = "INSERT INTO Patient(P_id,name,age,sex)" + " VALUES(@PID,@PName,@Age,@Sex)";
            string insertDoctor = "INSERT INTO Doctor(D_id,name,office)" + " VALUES(@DID,@Doctor,@Office)";
            string insertRecord = "INSERT INTO Record(R_id,discribe)" + " VALUES(@RID,@Dsicribe)";
            string insertRelation = "INSERT INTO Relation(id,D_id,R_id,P_id)" + " VALUES(@RelationID,@DID,@RID,@PID)";
            SqlCommand cmd = new SqlCommand(insertPatient, myConn);
            SqlCommand cmd1 = new SqlCommand(insertDoctor, myConn);
            SqlCommand cmd2 = new SqlCommand(insertRecord, myConn);
            SqlCommand cmd3 = new SqlCommand(insertRelation, myConn);
            //----------------病人参数-------------
            cmd.Parameters.Add("@PID",SqlDbType.VarChar,20);
            cmd.Parameters["@PID"].Value=this.textPID.Text.Trim();
            cmd.Parameters.Add("@PName",SqlDbType.VarChar,20);
            cmd.Parameters["@PName"].Value=this.textName.Text.Trim();
            cmd.Parameters.Add("@Age",SqlDbType.VarChar,20);
            cmd.Parameters["@Age"].Value=this.textAge.Text.Trim();
            cmd.Parameters.Add("@Sex",SqlDbType.VarChar,20);
            cmd.Parameters["@Sex"].Value=this.textSex.Text.Trim();
            //----------------医生参数--------------
            cmd1.Parameters.Add("@DID", SqlDbType.VarChar, 20);
            cmd1.Parameters["@DID"].Value = this.textDID.Text.Trim();
            cmd1.Parameters.Add("@Doctor", SqlDbType.VarChar, 20);
            cmd1.Parameters["@Doctor"].Value = this.textDoctor.Text.Trim();
            cmd1.Parameters.Add("@Office", SqlDbType.VarChar, 20);
            cmd1.Parameters["@Office"].Value = this.textOffice.Text.Trim();
            //----------------病例参数--------------
            cmd2.Parameters.Add("@RID", SqlDbType.VarChar, 20);
            cmd2.Parameters["@RID"].Value = this.textDiscribeID.Text.Trim();
            cmd2.Parameters.Add("@Dsicribe", SqlDbType.VarChar, 20);
            cmd2.Parameters["@Dsicribe"].Value = this.textDiscribe.Text.Trim();
            //----------------关联参数--------------
            cmd3.Parameters.Add("@PID", SqlDbType.VarChar, 20);
            cmd3.Parameters["@PID"].Value = this.textPID.Text.Trim();
            cmd3.Parameters.Add("@DID", SqlDbType.VarChar, 20);
            cmd3.Parameters["@DID"].Value = this.textDID.Text.Trim();
            cmd3.Parameters.Add("@RID", SqlDbType.VarChar, 20);
            cmd3.Parameters["@RID"].Value = this.textDiscribeID.Text.Trim();
            cmd3.Parameters.Add("@RelationID", SqlDbType.VarChar, 20);
            cmd3.Parameters["@RelationID"].Value = this.textRelationID.Text.Trim();            try
            {
                myConn.Open();
                cmd.ExecuteNonQuery();
                cmd1.ExecuteNonQuery();
                cmd2.ExecuteNonQuery();
                cmd3.ExecuteNonQuery();
                Response.Redirect("<h3 align=center>&nbsp;<a href=op.aspx>返回</a></h3>");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                myConn.Close();
            }
        }
    }
}

解决方案 »

  1.   

    人家是来求助的,楼上的何必JJWW呢,难道你就没从新手过来啊,
      

  2.   

    使用TransactionScope 事务操作,使用数据库操作类
    using(TransactionScope scope = new TransactionScope()) {} 
      

  3.   

    debug 一下,不要打激别人的热情
      

  4.   

    这样肯定不对,执行完一个command之后关闭connection,然后再开connection,才可以;你也可以用一个command,用command的commandtext属性,重新给command一个sql语句。
      

  5.   

    我刚才替你测试了一下,我用的SqlServer2000的数据库,  SqlConnection myConn = new SqlConnection("server=localhost\\SQLEXPRESS;database=HMS;uid=sa;pwd=123");
    我把\\SQLEXPRESS它去掉就可以了,不知道你的是怎么的,我去掉了以后就可以了,你去掉以后试试!
      

  6.   

    前边的几位说的确实.有点伤人自尊了 
    楼主找个 DBHelper就什么都解决了你能行
      

  7.   

    说白了现在的问题就是如果要用一条语句在mysql中表示把不同textBOX中的数据插入不同表中怎么搞,如果不能的话应该用什么方法?
      

  8.   

    楼主找个 DBHelper就什么都解决了
      

  9.   

    調試。。
    一個一個來。。
    四個Command先註釋掉。一個個放出來。
      

  10.   


    看你的链接语句分明是sqlserver的啊....mysql的Parameters 用? 
    string insertPatient = "INSERT INTO Patient(P_id,name,age,sex)" + " VALUES(@PID,@PName,@Age,@Sex)";
    换成
    string insertPatient = "INSERT INTO Patient(P_id,name,age,sex)" + " VALUES(?PID,?PName,?Age,?Sex)";cmd.Parameters.Add("@PID",SqlDbType.VarChar,20);
    换成cmd.Parameters.Add("?PID",SqlDbType.VarChar,20);
      

  11.   

    额~~我输入错了是sql server,我发现虽然有错误但是查数据库的表内容都输入了进去,这是怎么回事?
      

  12.   

    错了错了,是sql server,一不小心智能输入法输入错误
      

  13.   

                    Response.Redirect("<h3 align=center>&nbsp;<a href=op.aspx>返回</a></h3>");

    是这句话的错误吧     
    重定向 直接写地址
     Response.Redirect("op.aspx") 唉
      

  14.   

    要不你就改成   Response.Write("<h3 align=center>&nbsp;<a href=op.aspx>返回</a></h3>");
    都是前边误导  竟看数据库那块了 罪过啊