当前位置: 代码迷 >> .NET Framework >> 修改datagrid值有关问题.````
  详细解决方案

修改datagrid值有关问题.````

热度:80   发布时间:2016-05-02 00:52:49.0
修改datagrid值问题.急````
功能为选择datagrid某一条记录,该记录的值传给各个textbox,现在问题如下:首次修改记录成功,第二次选择datagrid某条记录,点修改按钮却出现异常``
代码如下:
private   void   button7_Click(object   sender,   System.EventArgs   e)
{
string   company_id   =   textBox3.Text;
string   companyName   =   textBox4.Text;
string   companyAddress   =   textBox5.Text;
string   tel   =   textBox6.Text;
string   fax   =   textBox7.Text;
string   linkMan   =   textBox8.Text;
string   postalcode   =   textBox9.Text;
string   website   =   textBox10.Text;
string   email   =   textBox11.Text;
string   bankAccounts   =   textBox12.Text;
string   taxNumber   =   textBox13.Text;
string   bank   =   textBox14.Text;
string   managementVariety   =   textBox15.Text;
string   settlementWay   =   textBox16.Text;
string   addDate   =   textBox17.Text;
string   comString   =   "update   CompanyInfo   set   Company_id   =   ' "+company_id+ " ',CompanyName   =   ' "+companyName+ " ',CompanyAddress   =   ' "+companyAddress+ " ',Tel   =   ' "+tel+ " ',Fax   =   ' "+fax+ " ',LinkMan   =   ' "+linkMan+ " ',Postalcode   =   ' "+postalcode+ " ',Website   =   ' "+website+ " ',Email   =   ' "+email+ " ',BankAccounts   =   ' "+bankAccounts+ " ',TaxNumber   =   ' "+taxNumber+ " ',Bank   =   ' "+bank+ " ',ManagementVariety   =   ' "+managementVariety+ " ',SettlementWay   =   ' "+settlementWay+ " ',AddDate   =   ' "+addDate+ " '   where   (Company_id   =   ' "+company_id+ " ') ";
SqlCommand   myCom   =   sqlConnection1.CreateCommand();
myCom.CommandText   =   comString;
try
{
myCom.ExecuteNonQuery();
int   n   =   this.sqlDataAdapter1.Fill(this.dataSet12, "Company_id ");
if(n==0)
{
MessageBox.Show( "添加失败,请与技术人员联系! ");
}
else
{
MessageBox.Show( "修改成功! ");
this.dataSet12.Clear();
this.sqlDataAdapter1.Fill(this.dataSet12, "厂商资料 ");
this.dataGrid2.DataSource   =   this.dataSet12;
this.dataGrid2.DataMember   =   "厂商资料 ";
this.dataGrid2.Refresh();
this.sqlConnection1.Close();
}
}
catch(Exception   b)
{
//MessageBox.Show(b.toString());
}
finally
{
}
sqlConnection1.Close();
}
如何解决,急急````

------解决方案--------------------
sqlConnection1关闭了?
------解决方案--------------------
1、sqlConnection1.Close();关闭了
2、第一次都更新成功,说明执行更新的语句没有问题,请跟踪 comString 的值,看第二次是否正确
  相关解决方案