我寫了一個小軟件,實現對某張數據表的增刪改查,單擊修改按鈕會彈出一個窗口,窗口裏顯示的資料是從上一個窗口中獲取的,修改新窗口裏面的資料單擊保存按鈕進行保存。但是軟件運行後修改資料後點擊保存按鈕程序就像死機了,無響應,我的保存按鈕單擊事件如下:
string str = "server=.......";
            using (OracleConnection conn = new OracleConnection(str))
            {
                try
                {
                    string xg = "update tbl_autoplay_list set FACT_NO=" + textBox6.Text + ",";
                    //xg += "ITEM_NO=" + textBox1.Text+ ",";
                    xg += "device_id=" + textBox5.Text + ",";
                    xg += "interval=" + textBox2.Text + ",";
                    xg += "play_url=" + "'"+textBox3.Text+"'" + ",";
                    xg += "play_timerange1=" + "'"+textBox7.Text +"'"+ ","; 
                    xg += "expect_timerange1=" +"'"+ textBox8.Text+"'" + ",";
                    xg += "memo=" + "'"+textBox4.Text+"'" + "   where item_no=" 
                        + textBox1.Text;
                    OracleDataAdapter oda = new OracleDataAdapter(xg, conn);
                    DataSet ds = new DataSet();
                    oda.Fill(ds, "tbl_autoplay_list");
                    //oda.Update(ds,"tbl_autoplay_list");
                    MessageBox.Show("保存成功!","提示!");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

解决方案 »

  1.   

    首先呢,你的sql语句丑的要死,而且会引发sql注入攻击漏洞。其次呢就是你报错的原因,你所有的字符串都没有打单引号,数据库里面里面查询的时候,所有字符串形式的值都要打双引号。你一个都没打,肯定报错啊
      

  2.   

     OracleConnection myConnection = new OracleConnection(str);
       OracleCommand myCommand = new OracleCommand(xg, myConnection);
       myCommand.Connection.Open();
       myCommand.ExecuteNonQuery();
       myConnection.Close();
       MessageBox.Show("保存成功!","提示!");