这里是我的代码......
但我得到的错误= da.fill(DS) if (this.MdiParent is MDIParent1)
{
MDIParent1 css = (MDIParent1)this.MdiParent;
try
{
if (Compcls.Gaction == "a")
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.Transaction = transaction;
string STR11 = "insert into ITEMMAST(ITEMCODE,COMPCODE)VALUES('" + textBox1.Text + "','" + Compcls.Gcomp_cd + "' )";
cmd = new SqlCommand(STR11,con,transaction);
cmd.ExecuteNonQuery();
string str = "select Ac_code,broktype,brokrate,trantype,tranrate, bcycle from accountd where COMPCODE='" + Compcls.Gcomp_cd + "'and brksys='s'";
SqlDataAdapter DA = new SqlDataAdapter(str, con);
DataSet ds = new DataSet();
DA.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string ac = ds.Tables[0].Rows[i][0].ToString();
string btype = ds.Tables[0].Rows[i][1].ToString();
string brate = ds.Tables[0].Rows[i][2].ToString();
string ttype = ds.Tables[0].Rows[i][3].ToString();
string trate = ds.Tables[0].Rows[i][4].ToString();
string ccycle = ds.Tables[0].Rows[i][5].ToString();
//string brksys = dt.Tables[0].Rows[i][0].ToString();
string query = "insert into PITBROK (compcode,Ac_code,broktype,brokrate,trantype,tranrate ,bcycle,ITEMCODE)VALUES('" + Compcls.Gcomp_cd + "','" + ac + "','" + btype + "','" + brate + "','" + ttype + "','" + trate + "','" + ccycle + "','" + textBox1.Text + "') ";
SqlCommand cmd22 = new SqlCommand(query, con, transaction);
cmd22.ExecuteNonQuery();
}
//MessageBox.Show("SAVED");
}
}
// transaction = con.BeginTransaction();
string act;
if (radioButton2.Checked == true)
{
act = "0";
}
else
{
act = "1";
}
string INSTP = cmbinstrutype.SelectedItem.ToString();
string insttype;
switch (INSTP)
{
case "FUTURE":
insttype = "F";
break;
case "OPTION":
insttype = "O";
break;
default:
insttype = "C";
break;
}
string STR22 = "UPDATE itemmast SET ITEMNAME='" + textBox2.Text + "',EXHCODE ='" + textBox5.Text + "' ,LOT ='" + textBox7.Text + "',EXCHANGECODE='" + comboBox1.SelectedValue.ToString() + "',PriceUnit='" + textBox8.Text + "', Regularlot='" + textBox11.Text + "',Qtyunit='" + textBox10.Text + "',Deliverylot='" + textBox12.Text + "',deliveryunit='" + textBox9.Text + "',active='" + act + "',INSTTYPE='" + insttype + "'WHERE ITEMCODE = '" + textBox1.Text + "'AND compcode='" + Compcls.Gcomp_cd + "'";
cmd = new SqlCommand(STR22,con,transaction);
cmd.ExecuteNonQuery();
transaction.Commit();
con.Close();
MessageBox.Show("RECORD SAVED", "Save Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
filllist();
panel1.Enabled = false;
}
catch (SqlException sqlError)
{
transaction.Rollback();
MessageBox.Show("operation stop due to error");
}
finally
{
con.Close();
}
}
ExecuteReader需要有一个交易时,分配给该命令的连接处于挂起的本地事务是命令。该命令的Transaction属性尚未初始化。
[编辑]喊删除 - OriginalGriff [/编辑]