本文介绍了如何解决方法名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
bool SQLExecuteBatch(string[] strQueryText) { bool Success = false; using (SqlConnection cnSQL = new SqlConnection(conStr)) { cnSQL.Open(); SqlCommand cmd = cnSQL.CreateCommand(); SqlTransaction stBatch; stBatch = cnSQL.BeginTransaction("SampleTransaction"); cmd.Connection = cnSQL; cmd.Transaction = stBatch; try { for (int i = 0; (i <= (strQueryText.Length - 1)); i++) { cmd.CommandText = strQueryText(i); cmd.ExecuteNonQuery(); } stBatch.Commit(); Success = true; } catch (Exception ex1) { Cursor.Current = Cursors.Default; MessageBox.Show(("SQLExecuteBatch request can not be performed due to the following..." + ("\r" + ("\r" + (ex1.Message + ("\r" + ("\r" + "Changes were not applied to the target data.")))))), "Database Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); try { stBatch.Rollback(); } catch (Exception ex2) { Cursor.Current = Cursors.Default; MessageBox.Show(("SQLExecuteBatch rollback attempt failed..." + ("\r" + ("\r" + ex2.Message))), "Database Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } Success = false; } } return true; }
我有问题strQueryText
im having problem strQueryText
for (int i = 0; (i <= (strQueryText.Length - 1)); i++) { cmd.CommandText = strQueryText(i); cmd.ExecuteNonQuery(); }我的尝试: i已经尝试了我所知道的一切
What I have tried: i have tried everything i know
推荐答案C#使用方括号进行数组索引,而不是舍入。尝试: C#uses square brackets for array indexing, not round. Try: cmd.CommandText = strQueryText[i];
更多推荐
如何解决方法名称空间
发布评论