本文介绍了如何在此查询中使用回滚...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void savegrid()
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
StringBuilder query = new StringBuilder("delete from PITBROK ");
query.AppendFormat("where ");
for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
{
int coun = checkedListBox1.CheckedItems.Count;
coun = coun - 1;
string val;
if (checkedListBox1.CheckedItems.Count > 0)
{
DataRow row;
row = ((DataRowView)this.checkedListBox1.CheckedItems[i]).Row;
val = (row[this.checkedListBox1.ValueMember]).ToString();
row = null;
query.AppendFormat("PITBROK.AC_CODE='{0}' ", val.ToString());
if (i < coun)
{
query.AppendFormat(" or ");
}
}
}
if (checkedListBox3.CheckedItems.Count > 0)
{
query.Append("AND ");
}
for (int k = 0; k < checkedListBox3.CheckedItems.Count; k++)
{
int coun1 = checkedListBox3.CheckedItems.Count;
coun1 = coun1 - 1;
query.AppendFormat("PITBROK.ITEMCODE='{0}'", checkedListBox3.CheckedItems[k]);
if (k < coun1)
{
query.Append("or ");
}
}
query.Append(" and compcode='" + Compcls.Gcomp_cd + "' ");
string sql = query.ToString();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
for (int a = 0; a < dataGridView1.Rows.Count - 1; a++)
{
string item11 = dataGridView1[0, a].Value.ToString();
string broktype11 = dataGridView1[1, a].Value.ToString();
string brokrate11 = dataGridView1[2, a].Value.ToString();
string tranrate = dataGridView1[3, a].Value.ToString();
string trantype11 = dataGridView1[4, a].Value.ToString();
//string setdate11 = dataGridView1[5, a].Value.ToString();
DateTime t = Convert.ToDateTime(dataGridView1[5, a].Value.ToString());
string z = t.Date.ToString("dd/MM/yyyy");
string martype11 = dataGridView1[6, a].Value.ToString();
string marrate11 = dataGridView1[7, a].Value.ToString();
SqlCommand cmd1 = new SqlCommand("select AC_codefrom accountm where name ='" + dataGridView1[8, a].Value.ToString() + "'and compcode='" + Compcls.Gcomp_cd + "' ", con);
string ACcode = Convert.ToString(cmd.ExecuteScalar());
cmd.CommandText = ("insert into PITBROK (COMPCODE,ITEMCODE, BROKTYPE,BROKRATE,TRANRATE,TranType,uptostdt,MARTYPE,MARRATE,AC_CODE) values('" + Compcls.Gcomp_cd + "','" + item11 + "','" +broktype11 + "','"+brokrate11+"','"+tranrate+"','"+trantype11+"','"+z+"','"+martype11+"','"+marrate11+"','"+ACcode+"') ");
cmd.ExecuteNonQuery();
MessageBox.Show("done");
// toolTip1.IsBalloon = true;
//toolTip1.ToolTipIcon = ToolTipIcon.Info;
//toolTip1.ToolTipTitle = "Success";
//toolTip1.Show("Record Saved", panel3, 0, 0, 1000);
}
}
谢谢Advanced
thanks in advanced
推荐答案
这篇关于如何在此查询中使用回滚...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!