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类型)

解决方案 »

  1.   

    decimal.Parse(this.textBox10.Text) + "','" + decimal.Parse((this.textBox11.Text )
      

  2.   

    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 + "')"; 把这条语句考过去用用看。
      

  3.   

       如果数据库里的字段是 int  decimal  money 等类型  在values( )里不需要  ‘’
      

  4.   

    先转换类型,Convert.ToDecimal(this.TextBox10.Text)
    如果是decimal类型字段,就不要在添加''