c# sql 无法将 varchar 转换为 int(找到解决方法)

c# sql cannot convert varchar to int (Found a work around)

我正在尝试将一些数据插入 sql 服务器,并且代码工作正常,直到我在末尾添加了 @instel。当我添加我收到错误 "Error converting data type varchar to numeric." 时,即使我将文本框留空也是如此。

我把它作为一个文本框,但由于我收到错误,我试图将它作为一个变量,但它仍然没有解决问题。该代码适用于要插入的 REL,它也是一个 int。 REL 和@instel 的数据库和文本框属性也相同。我还尝试将变量设为 int,但它没有任何改变。如果有人知道这是为什么并且可以帮助我解决问题。

 SqlCommand slMEVO_NAW = new SqlCommand(@"insert into NAW(REL,NAAM,BTW_CODE,TAV,STR,PL,LAND,PLBOX,TAAL,COUNTRY_C,TEL,FAX,EMAIL,XMAS,TEL2,STR1,INSTELINCL,INCOTERMS,PRODDAT,INSTEL) values('" + this.Txtbx_RelNmmr.Text + "','" + this.Txtbx_Bedrijf.Text + "','" + this.Txtbx_BtwCode.Text + "','" + this.Txtbx_Tav.Text + "','" + this.Txtbx_HuisAdres.Text + "','" + this.Txtbx_PstCde.Text + "','" + this.Txtbx_Land.Text + "','" + this.Txtbx_PstBs.Text + "','" + this.Txtbx_Taal.Text + "','" + this.Txtbx_LndCode.Text + "','" + this.Txtbx_Telnmmr.Text + "','" + this.Txtbx_Fax.Text + "','" + this.Txtbx_Email.Text + "','" + this.Txtbx_Xmas.Text + "','" + this.Txtbx_telnmmr2.Text + "','" + this.Txtbx_BezAdres.Text + "','" + this.TBX_Instelkstn.Text + "','" + this.Txtbx_Incot.Text + "','" + this.TBX_PrdctDtm.Text + "','@INSTEL' );", Connectie.connMEVO_NAW);
            slMEVO_NAW.Parameters.Add("@INSTEL", SqlDbType.VarChar).Value = Txtbx_InstelKsten.Text;

修复 似乎在我将它更改为所有参数后,如果文本框为空,它只会给出错误,所以我只是让程序在它现在进行查询之前将文本设置为 0

您table中的字段类型可能是 Integer 或 Numeric,请更改为 Varchar。

正如我在主文中所说 post 经过编辑我找到了解决问题的方法

修复似乎在我将它更改为所有参数后它只在文本框为空时给出错误所以我只是让程序在它现在进行查询之前将文本设置为 0