可以只看最后这一段代码
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
  comboBox1.Text = comboBox1.SelectedItem.ToString();
  }  private void btnNew_Click(object sender, EventArgs e[color=#FF0000])//保存信息到CAD_IP_PatientNotice,就是这里click后,数据库中没有插入数据 [/color]{
  try
  {
  SqlConnection conn5 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\db.mdf;Integrated Security=True;User Instance=True");
  conn5.Open();
  string strInsert = "INSERT INTO [CAD_IP_PatientNotice] (iPatientID,vPatientName,cPatientSex,iPatientAge,vPatientCellphone,vPatientIdentifyCard,iSpecialPatient,vDiagnose,vAttending)VALUES('" + txtPID.Text + "','" + lblPName.Text + "','" + lblPSex.Text + "','" + lblPAge.Text + "','" + lblPPhone.Text + "','" + lblPID.Text + "','" + lblSpecial.Text + "','" + txtDiagnose.Text + "','" + comboBox1.Text + "')";
  SqlCommand cmd5 = new SqlCommand(strInsert, conn5);
  DataSet ds5 = new DataSet("CAD_IP_PatientNotice");
    
  SqlDataAdapter sda5 = new SqlDataAdapter(cmd5);
  sda5.InsertCommand = new SqlCommand(strInsert, conn5);
  sda5.Fill(ds5, "CAD_IP_PatientNotice");
  DataTable dt = ds5.Tables["CAD_IP_PatientNotice"];
  //SqlCommandBuilder scb5 = new SqlCommandBuilder(sda5);
  sda5.Update(ds5.Tables["CAD_IP_PatientNotice"]);
    
    
  if (cmd5.ExecuteNonQuery() > 0)
  {
  MessageBox.Show("开单成功!", "提示");  }
  else
  {
  MessageBox.Show("开单失败,请完整填写住院通知单!", "提示");
  }
  sda5.Dispose();
  ds5.Dispose();
  dt.Dispose();
  conn5.Close();
    
  }
  catch (Exception x)
  {
  MessageBox.Show("错误" + x.ToString(), "error");
  }
    
  }  }

解决方案 »

  1.   

    SqlConnection conn5 = new SqlConnection("Data Source......
    SqlCommand cmd5 = new SqlCommand(strInsert, conn5);
    conn5.Open();
    int rowCount=cmd5.ExecuteNonQuery();
    conn5.close();if (rowCount>0)
    ......
      

  2.   

    另外,你用的是连接数据库文件,确保每次生成不会把数据库文件重新复制到生成的目录(mdf我不确定,Access就有这样的情况),造成每次调试,上一次调试操作的数据都不见了。
      

  3.   

    我的错误是system.ArgumentNullException:值不能为空。但我要插入的表中的ID号我设为自动增长的可还是错误。
    你说的我试过了,貌似不行。
      

  4.   

    首先你的机器上要有sql server数据库。数据库服务已经运行。
    第二,你的sqlconnection string写错了。
                string strConn = "server=127.0.0.1;database=TestWebServ;pwd=sa;uid=sa";
                Conn.ConnectionString = strConn;
                string strSql = "select * from tNodeInfo where ID='" + ID + "' and Password='" + EnKeyCoke + "'";
                Conn.Open();            SqlDataAdapter ad = new SqlDataAdapter(strSql, Conn);
                ad.Fill(ds);
      

  5.   

    要更新  是不是没给数据啊
    sda5.InsertCommand = new SqlCommand(strInsert, conn5);
    sda5.Fill(ds5, "CAD_IP_PatientNotice");
    DataTable dt = ds5.Tables["CAD_IP_PatientNotice"];
    //SqlCommandBuilder scb5 = new SqlCommandBuilder(sda5);
    sda5.Update(ds5.Tables["CAD_IP_PatientNotice"]);报的是参数空了
      

  6.   

    既然ID时自增的,把iPatientID和txtPID.Text去掉另外不建议这么写sql,有好多弊端。强烈建议你用SqlParamter
      

  7.   

    确实是啊,LZ最起码把错误信息给贴出来啊,这么长的黑字谁受的了啊
    还有就是数据库连接字符串用这么多次也不嫌麻烦啊对于标题党,肯定是不可能的,Sql Express也包含一些基础的sql server功能的
      

  8.   

    很热闹啊,直接一个ExecuteNonQuery不就OK了啊,你的sql种的comboBox1.Text 换成comboBox1.SelectedItem.ToString();看看
      

  9.   


    赞同
    注:一般都不用VS自带的,SQl2005 最好还是自己装一个,
      

  10.   

    我认为是我的插入数据有问题。可是有问题的数据就是那个自增长的ID列,所以,不知道该怎么办。
    声明,第一,老师要求的VS自带的sql express。
    第二,报的错误是system.ArgumentNullException:值不能为空。出错行:datatable
      

  11.   


    txtPID不是主键,主键我没插
      

  12.   

    可是我用的是VS自带的啊,而且是winform。连接字符串应该是没有问题的