Friday, February 17, 2012

empty values in SQL sentence

i have insert/update SQL sentence, but sometimes there are empty values because there not required in the database so sometimes the sql sentence look this way:

INSERT INTO EquipmentAndPlace (EquipmentID,EquipmentEmdaNo,EquipmentPlace,EquipmentIDForRecognize, EquipmentRemarks,EquipmentLastChecked) VALUES ('3','','2','1','','12/1')

with empty values, but then it doent update in the dataBase-only if all the values appear-
what the solution of it?
ThanksCan you show us the whole part of your insert code. what kind of methods you used.

Alotaibi|||hi, u could build a dynamic SQL for this kind of problem. A stored procedure would be the best bet but let me know if u are using a sp or a SQL query inside your code. depending upon the values u pass to the stored proc, u could add the fields that need to be there in ur query. let me know if u want me to send the sp.|||for example in this code only if i have all the values its work-otherwise it doesnt update-the same thing happend if i want to insert new row data to dataBase.
shravan79 - im a beginner in ASP .net-i dint work yet with stored procedure , my senteces are SQL sentences...
as i said-this value are not requried in the database

function UpdateDataStore(e as DataGridCommandEventArgs) _
as boolean

dim i,j as integer
dim sDate1,sDone,sPeopleName,sResponse,sNextDate,sImidiate as string
dim strText,sDate2,sAmlazot,sAct,sDesc as string
dim blnGo as boolean = true
dim lbGroupTemp,lbPlaceTemp,lbTypeTemp,lbLevelTemp as ListBox
dim lbCostTemp,lbResponsableTemp,lbMainGroup As ListBox

sDate1 = CType(e.Item.Cells(2).Controls(0), TextBox).Text
sDone = CType(e.Item.Cells(3).Controls(1), checkBox).checked
sPeopleName = CType(e.Item.Cells(4).Controls(0), TextBox).Text
sResponse = CType(e.Item.Cells(5).Controls(0), TextBox).Text
sNextDate = CType(e.Item.Cells(6).Controls(0), TextBox).Text
sDate2 = CType(e.Item.Cells(9).Controls(0), TextBox).Text
sImidiate = CType(e.Item.Cells(10).Controls(1), checkBox).checked
sAmlazot = CType(e.Item.Cells(13).Controls(1), TextBox).Text
sAct = CType(e.Item.Cells(14).Controls(1), TextBox).Text
sDesc = CType(e.Item.Cells(19).Controls(1), TextBox).Text

'get the list box info
lbGroupTemp=e.Item.Cells(23).Controls(1)

if lbGroupTemp.SelectedIndex = -1 then
lbGroupTemp.SelectedIndex=0
end if
'get the list box info
lbPlaceTemp=e.Item.Cells(21).Controls(1)

if lbPlaceTemp.SelectedIndex = -1 then
lbPlaceTemp.SelectedIndex=0
end if
'get the list box info
lbTypeTemp=e.Item.Cells(18).Controls(1)

if lbTypeTemp.SelectedIndex = -1 then
lbTypeTemp.SelectedIndex=0
end if
'get the list box info
lbLevelTemp=e.Item.Cells(16).Controls(1)

if lbLevelTemp.SelectedIndex = -1 then
lbLevelTemp.SelectedIndex=0
end if
'get the list box info
lbCostTemp=e.Item.Cells(12).Controls(1)

if lbCostTemp.SelectedIndex = -1 then
lbCostTemp.SelectedIndex=0
end if
'get the list box info
lbResponsableTemp=e.Item.Cells(8).Controls(1)

if lbResponsableTemp.SelectedIndex = -1 then
lbResponsableTemp.SelectedIndex=0
end if
'get the list box info
lbMainGroup=e.Item.Cells(25).Controls(1)

if lbMainGroup.SelectedIndex = -1 then
lbMainGroup.SelectedIndex=0
end if

dim strSQL as string = "UPDATE SSFactory SET " & _
"SSTypeID = '" & lbGroupTemp.selectedValue & "'," & _
"PlaceId = '" & lbPlaceTemp.selectedValue & "'," & _
"SSMaintypeID = '" & lbMainGroup.selectedValue & "'," & _
"SSDesc = '" & sDesc & "'," & _
"SSTypeID1 = '" & lbTypeTemp.selectedValue & "'," & _
"SSShouldHandleID = '" & lbLevelTemp.selectedValue & "'," & _
"SSHamlatzot = '" & sAmlazot & "'," & _
"SSCostID = '" & lbCostTemp.selectedValue & "'," & _
"SSDateToHandle = '" & sDate2 & "'," & _
"SSResposible = '" & sResponse & "'," & _
"SSFactoryAction = '" & sAct & "'," & _
"SSPeopleName = '" & sPeopleName & "'," & _
"SSDateWasDone = '" & sDate1 & "'," & _
"SSDateShouldCheck = '" & sNextDate & "'" & _
" WHERE SSFactoryID = " & dgData.DataKeys(e.Item.ItemIndex)
response.write(strSQL)
'exit function
ExecuteStatement(strSQL)
return blnGo
end function

Thanks a lot!!!!|||please someone-i dont understand why if i have empty values its doesnt work...HELP!!

No comments:

Post a Comment