Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

C# + Oracle.DataAccess.Client - not responding executing sql update statement

I'm trying to update some fields(previously selected and displayed in DataGridView). For some reason WinForms application not responding when i'm trying to execute sql update statement (ExecuteNonQuery). Anything wrong with my code?

private void button19_Click(object sender, EventArgs e)
    {        
        if (ora_dataset.Tables["SWAP_2G_CELLS"].Rows.Count > 0)
        {
           foreach (DataRow row in ora_dataset.Tables["SWAP_2G_CELLS"].Rows)
           {
               string swap = row.ItemArray[13].ToString();
               string flag = row.ItemArray[14].ToString();
               string data = row.ItemArray[15].ToString();

               string sql_update = System.IO.File.ReadAllText("SQL/SWAP/swap_2g_update.dat");

               sql_update = sql_update.Replace("%SWAP_PARAM%", swap);
               sql_update = sql_update.Replace("%FLAG_PARAM%", flag);
               sql_update = sql_update.Replace("%DATE_PARAM%", data);
               sql_update = sql_update.Replace("%SITE_ID_PARAM%", row.ItemArray[1].ToString());
               sql_update = sql_update.Replace("%LAC_PARAM%", row.ItemArray[7].ToString());

               OracleCommand cmd = new OracleCommand();
               OracleConnection con = new OracleConnection(connstring);
               cmd.Connection = con;
               //cmd.CommandType = CommandType.Text;
               cmd.CommandText = sql_update;
               cmd.Connection.Open();
               int count = cmd.ExecuteNonQuery();
               cmd.Connection.Close();
               cmd.Dispose();
           }
        }

After parameters replacement sql string looks like this for first row in my dataset:

UPDATE SWAP_2G
SET 
SWAP = 'P'
,FLAG1 = '1'
,DATA_SWAP = TO_DATE('12-02-15 00:00:00', 'dd-mm-yy hh24:mi:ss')
WHERE SITE_ID = '2664' AND LAC LIKE '39002'

I'm trying to execute it with Oracle SQL Developer, and it's work fine.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...