Click here to Skip to main content
15,913,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
insert into ItemMaster
( ITEM_CODE,
ITEM_NAME,
 DRAWING_NO,
 WEIGHT_CAST,
 WEIGHT_FINISH,
CROSSING_COUNT,
catID )
values('a','a','','','','','')


getting error when passing null values for numeric fields thats is weightcast ans weightfinish
Posted
Comments
Salman622 30-May-14 6:11am    
numeric fields do not take value with single code
if you know the value is null
then simple pass 0 or Null
eg.
insert into ItemMaster
( ITEM_CODE,
ITEM_NAME,
DRAWING_NO,
WEIGHT_CAST,
WEIGHT_FINISH,
CROSSING_COUNT,
catID )
values('a','a','',0,0,'','')

else you can use

insert into ItemMaster
( ITEM_CODE,
ITEM_NAME,
DRAWING_NO,
WEIGHT_CAST,
WEIGHT_FINISH,
CROSSING_COUNT,
catID )
values('a','a','',Null,Null,'','')

'' is not a NULL value, have a try at the statement below:

SQL
insert into ItemMaster
( ITEM_CODE,
ITEM_NAME,
 DRAWING_NO,
 WEIGHT_CAST,
 WEIGHT_FINISH,
CROSSING_COUNT,
catID )
values('a','a','',null,null,'','')
 
Share this answer
 
Comments
Adesh Saroha 30-May-14 6:19am    
strSql = "insert into ItemMaster(" & _
" ITEM_CODE," & _
" ITEM_NAME," & _
" DRAWING_NO," & _
" WEIGHT_CAST," & _
" WEIGHT_FINISH," & _
" CROSSING_COUNT," & _
" catID" & _
" )" & _
" values(" & _
"'" & Replace(txtItemCode.Text, "'", "''") & "'," & _
"'" & Replace(txtItemName.Text, "'", "''") & "'," & _
"'" & Replace(txtDrawingNo.Text, "'", "''") & "'," & _
"'" & Replace(txtStWeightCst.Text, "'", "''") & "'," & _
"'" & Replace(txtStWeightFin.Text, "'", "''") & "'," & _
"'" & Replace(txtNoOfCross.Text, "'", "''") & "'," & _
"'" & IIf(cboItemCategoty.SelectedIndex = -1, "", cboItemCategoty.SelectedValue) & "'" & _
")" actually i am writing this code as like this vb
hypermellow 30-May-14 6:33am    
I've not wrote any VB for a while, but something link this should help:

strSql = "insert into ItemMaster(" & _
" ITEM_CODE," & _
" ITEM_NAME," & _
" DRAWING_NO," & _
" WEIGHT_CAST," & _
" WEIGHT_FINISH," & _
" CROSSING_COUNT," & _
" catID" & _
" )" & _
" values(" & _
"'" & Replace(txtItemCode.Text, "'", "''") & "'," & _
"'" & Replace(txtItemName.Text, "'", "''") & "'," & _
"'" & Replace(txtDrawingNo.Text, "'", "''") & "'," & _
"'" & Replace(txtStWeightCst.Text, "'", "''") & "'," & _
IIf((txtStWeightFin.Text.Length=0), "NULL", string.concat("'", Replace(txtStWeightFin.Text, "'", "''") & "',") & _
IIf((txtNoOfCross.Text.Length=0), "NULL", string.concat("'", Replace(txtNoOfCross.Text, "'", "''") & "',") & _
"'" & IIf(cboItemCategoty.SelectedIndex = -1, "", cboItemCategoty.SelectedValue) & "'" & _
")" actually i am writing this code as like this vb
Make sure that you are mapping the correct values to the respected columns in the insert statement.

as varchar,nvarchar and date columns will take the values enclosed with single quotes. eg ( 'abc' )
numeric data columns you should pass the default values(0). eg( 1,3)
 
Share this answer
 
Comments
Adesh Saroha 30-May-14 6:29am    
how to write condition to pass null value if iam not inserting anything

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900