首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

从数据类型 varchar 转换为 numeric 时出错。该如何解决

2012-01-20 
从数据类型 varchar 转换为 numeric 时出错。?private void btntianjia_Click(object sender, EventArgs e)

从数据类型 varchar 转换为 numeric 时出错。?
private void btntianjia_Click(object sender, EventArgs e)
  {
   

  try
  {
  DataAccess ds=new DataAccess ();
  string str = ds.connection();
  con = new SqlConnection(str);
  con.Open();
  string Sql = "insert into ygjbtable(yggh,xingming,nianling,jiguan,shenfz,bumeng,zhiwei,jinctime,jbgz,gongb,jishi,lictime,bz) values('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "','" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + this.textBox8.Text + "','" + this.textBox9.Text + "','" + this.textBox10.Text + "','" + this.textBox11.Text + "','" + this.textBox12.Text + "','" + this.textBox13.Text + "')";


  SqlCommand cmd = con.CreateCommand();
  cmd.CommandType = CommandType.Text;
  cmd.CommandText = Sql;
  cmd.ExecuteNonQuery();
  }
  catch (Exception ex)
  {

  MessageBox.Show(ex.Message);
  }


  }

出错错误提示:从数据类型 varchar 转换为 numeric 时出错。

(字段里面只有gongb,jishi的数据类型是decimal类型)

[解决办法]
decimal.Parse(this.textBox10.Text) + "','" + decimal.Parse((this.textBox11.Text )

热点排行