2016-05-31 157 views
0

我打算從一個不同的表中向我的文本框插入一個特定的值。在這樣做的時候,它給了我一個錯誤:「在將varchar值5000轉換爲數據類型int時轉換失敗。在我的數據庫中,creditrequest列(5000)是char並且目標列是int。這樣的任何技巧?轉換varchar值時轉換失敗

這裏是我的代碼:?

protected void Button2_Click(object sender, EventArgs e) 
    { 
     using (SqlConnection scn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True")) 
     { 
      scn.Open(); 
      SqlCommand cmd = new SqlCommand("INSERT INTO UserData(CreditRequest) Select CreditRequest FROM CreditRequests Where [email protected]", scn); 
      cmd.Parameters.Add("@Username", SqlDbType.NVarChar).Value = Session["New"]; 

      object value = cmd.ExecuteScalar(); 

      if (value != null) 
       txtCredit.Text = value.ToString(); 
     } 

誤差與

object value = cmd.ExecuteScalar(); 

回答

0
INSERT INTO UserData(CreditRequest) SELECT CAST(REPLACE(CreditRequest, ',', '') as int) FROM CreditRequests Where [email protected] 
+0

所有報價中 –

+0

是,與更新您的SQL – ChrisBint

+0

同樣的錯誤SI。河 –

相關問題