Ошибка преобразования типа данных varchar в числовой - PullRequest
0 голосов
/ 22 марта 2012

Я получаю ошибку в следующем запросе:

insert into ProductStone ( Pieces, Weight, CutChg, LotID, 
                           CatID, OrnID, StoneID, ShadeID, CutID, ChgType, SetID) 
 values (  '10',  '0.3',  'null',  '601',  'H',  '101',  
           'S',  '0',  '13',  'null',  '4' ).

Проблема в том, что я создаю свой запрос во время выполнения. Скажите, пожалуйста, как я могу проверить, является ли значение нулевым или нет во время выполнения.

Часть моего кода, который я использую для построения динамического запроса во время выполнения, выглядит следующим образом. Я изменил свой предыдущий код, но в некоторых случаях он работает, а в некоторых случаях не работает с нулевыми значениями.

  if ((updatedData.elementAt(r).get(c).get(1)==null) ||
      (updatedData.elementAt(r).get(c).get(1).equals("")))
  {
      updatedData.elementAt(r).get(c).set(1,"0");
  }
  else if (!(updatedData.elementAt(r).get(c).get(1).toString().equalsIgnoreCase("null") )) 
  {
      updatedData.elementAt(r).get(c).set(1,"0");   
  }

Ответы [ 2 ]

1 голос
/ 22 марта 2012
if((updatedData.elementAt(r).get(c).get(1)==null) || (updatedData.elementAt(r).get(c).get(1).equals("")))
           {
             updatedData.elementAt(r).get(c).set(1,null);
           }

Измените этот кусок кода и проверьте ...

Еще одна точка

insert into ProductStone ( Pieces, Weight, CutChg, LotID, 
CatID, OrnID, StoneID, ShadeID, CutID, ChgType, SetID) 
 values (  '10',  '0.3',  'null',  '601',  'H',  '101',  
'S',  '0',  '13',  'null',  '4' ).

Когда вы вставляете нулевое значение, не помещайте это в кавычки, преобразуйте это в следующее утверждение и отметьте

insert into ProductStone ( Pieces, Weight, CutChg, LotID, 
CatID, OrnID, StoneID, ShadeID, CutID, ChgType, SetID) 
 values (  '10',  '0.3',  null,  '601',  'H',  '101',  
'S',  '0',  '13',  null,  '4' ).
0 голосов
/ 23 марта 2012

Моя проблема решается с помощью двух проверок

//First
if ((updatedData.elementAt(r).get(c).get(1).toString().equals("null"))) 
{
updatedData.elementAt(r).get(c).set(1,"0");   
}
//Second
if (!(updatedData.elementAt(r).get(c).get(1).toString().equals("null"))) 
{
updateQuery +=updatedData.elementAt(r).get(c).get(0)+"='"+updatedData.elementAt(r).get(c).get(1)+"', " ;
insertColValsStr += " '"+updatedData.elementAt(r).get(c).get(1)+"') ";        
}
else
{
updateQuery += updatedData.elementAt(r).get(c).get(0)+"=null " ;
insertColValsStr += " null ) " ;       
}
...