String SQLStatement= "if exists(select lc_sn from LC_patient where lc_sn='"+@lc_sn+"')"
       +"update LC_patient set visit_no='"+@visit+"',cname='"+@cname+"',home_tel='"+@tel+"',corp_name='"+@corp+"',home_address='"+@address+"' where lc_sn='"+@lc_sn+"'"
                   +"else insert into LC_patient(lc_sn,entry_no,visit_no,patient_sn,cname,birth_date,home_tel,gender,corp_name,home_address) values("+@lc_sn+",'0','"+@visit+"','"+@patient+"','"+@cname+"','"+@birth+"','"+@tel+"','"+@gender+"','"+@corp+"','"+@address+"')";

解决方案 »

  1.   

    String SQLStatement = "if exists(select lc_sn from LC_patient where lc_sn='" + @lc_sn + "')";
                SQLStatement += "update LC_patient set visit_no='" + @visit + "',cname='" + @cname + "',home_tel='" + @tel + "',corp_name='" + @corp + "',home_address='" + @address + "' where lc_sn='" + @lc_sn + "'";
                SQLStatement += "else insert into LC_patient(lc_sn,entry_no,visit_no,patient_sn,cname,birth_date,home_tel,gender,corp_name,home_address) values(" + @lc_sn + ",'0','" + @visit + "','" + @patient + "','" + @cname + "','" + @birth + "','" + @tel + "','" + @gender + "','" + @corp + "','" + @address + "')"; 
      

  2.   

    String SQLStatement = "if exists(select lc_sn from LC_patient where lc_sn='" + @lc_sn + "')";
      SQLStatement += "update LC_patient set visit_no='" + @visit + "',cname='" + @cname + "',home_tel='" + @tel + "',corp_name='" + @corp + "',home_address='" + @address + "' where lc_sn='" + @lc_sn + "'";
      SQLStatement += "else insert into LC_patient(lc_sn,entry_no,visit_no,patient_sn,cname,birth_date,home_tel,gender,corp_name,home_address) values(" + @lc_sn + ",'0','" + @visit + "','" + @patient + "','" + @cname + "','" + @birth + "','" + @tel + "','" + @gender + "','" + @corp + "','" + @address + "')"; 
      

  3.   

    1楼,2楼写个功能跟我的没差别呀。
    运行的时候还是提示SQL语句错误。
    我想实现的功能是:点提交时,如果数据库中存在一条lc_sn对应的数据,就执行更新,否则执行插入。
      

  4.   

    我数据库用的是Oracle的。请路过的大侠指点啊!顶一下!
      

  5.   

    我上网查资料大多是写begin语句的,我不知道在类里面怎么写。 static public DataSet UpdatePatient(int @lc_sn,string @visit,string @patient,string @cname,string @birth,string @tel,string @gender,string @corp,string @address)
    {//提交患者信息
    string SQLStatement= "if exists(select lc_sn from LC_patient where lc_sn='"+@lc_sn+"')"
           +"update LC_patient set visit_no='"+@visit+"',cname='"+@cname+"',home_tel='"+@tel+"',corp_name='"+@corp+"',home_address='"+@address+"' where lc_sn='"+@lc_sn+"'"
                       +"else insert into LC_patient(lc_sn,entry_no,visit_no,patient_sn,cname,birth_date,home_tel,gender,corp_name,home_address) values("+@lc_sn+",'0','"+@visit+
                       "','"+@patient+"','"+@cname+"','"+@birth+"','"+@tel+"','"+@gender+"','"+@corp+"','"+@address+"')";
    OracleDataAdapter oda = new  OracleDataAdapter(SQLStatement,oracleconn);
    DataSet dstPatient= new DataSet();
    oda.Fill(dstPatient);
    return dstPatient;
    }
      

  6.   

    我强烈建议你不再使用+符号,改用string.format()
    以前我遇到很多用+号写sql语句,一旦sql很长总是报错,后来使用string.format(问题解决了
      

  7.   


    这个具体怎么写?我用的是oracle数据库,我那样写可以么?是不是要重新定义参数什么的?
      

  8.   

    sql语句不提倡很复杂,能不在sql里就尽量不要再sql里
      

  9.   

    在这一行SQL语句上加断点调试,然后把SQLStatement接收到的值复制到数据库中看看报的什么错误,根据错误再去查找什么地方出错了。~
      

  10.   

    我自己还是写在package里面研究研究吧