即時嘗試插入一些數據到sql服務器和代碼工作正常,直到我在最後添加@instel。當我添加,我得到了錯誤「錯誤轉換數據類型varchar到數字。」即使我把文本框留空。c#sql無法將varchar轉換爲int(找到工作)
我把它作爲一個文本框,但因爲我得到了錯誤,我試圖把它作爲一個變量,但它仍然沒有解決問題。該代碼適用於要插入的REL,這也是一個int。 REL和@instel的數據庫和文本框屬性也是相同的。我也試圖讓變量爲int,但它沒有改變任何東西。如果有人知道這是爲什麼,可以幫助我,它會被appriciated。
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;
FIX 似乎它後,我改變了所有的參數,只給出瞭如果文本框爲空,所以我只是做節目的文字設置爲0,它的查詢之前,現在
SQL注入警報。您需要先修改您的SQL查詢,以便使用所有參數,而不是連接字符串。 – 2015-02-06 12:43:33
不要引用它; '+「,@INSTEL);' - 但*更重要的是*參數化所有其他值 – 2015-02-06 12:43:38
我試圖刪除@instel周圍,但它仍然沒有工作,我知道關於改變其餘的變量,但我仍然試圖讓它在我這樣做之前工作 – maam27 2015-02-06 12:45:45