reverendleo
06-08-2005, 02:22 PM
Thanks Miranda! On the ball as usual, you are.
I tried to basically copy the last page you assisted me with in writing a new page that will work similarly. I'm having a slight issue, though. My SaveRec command is giving me an "Input String was not in correct format" error.
Here's the code:
Function SJ(ByVal JobName as String, ByVal City as String, ByVal ST as String, ByVal County as String, ByVal DT as Date, _
ByVal PermitNum as String, ByVal ProjManName as String, ByVal Title as String, ByVal Inspector as String, _
ByVal InspQual as String, ByVal TypeofWork as String, ByVal DescriptionofActivity as String, _
ByVal Act1 as String, ByVal Act1StartDate as String, ByVal Act1EndDate as String, _
ByVal Act2 as String, ByVal Act2StartDate as String, ByVal Act2EndDate as String, _
ByVal Act3 as String, ByVal Act3StartDate as String, ByVal Act3EndDate as String, _
ByVal Act4 as String, ByVal Act4StartDate as String, ByVal Act4EndDate as String, _
ByVal Act5 as String, ByVal Act5StartDate as String, ByVal Act5EndDate as String, _
ByVal Act6 as String, ByVal Act6StartDate as String, ByVal Act6EndDate as String, _
ByVal Act7 as String, ByVal Act7StartDate as String, ByVal Act7EndDate as String, _
ByVal Act8 as String, ByVal Act8StartDate as String, ByVal Act8EndDate as String, _
ByVal TotalArea as Single, ByVal AreatobeDisturbed as Single, ByVal AreaOffSite as Single, _
ByVal ExVeg1 as String, ByVal ExVeg1Den as Single, ByVal ExVeg1Cov as Single, _
ByVal ExVeg2 as String, ByVal ExVeg2Den as Single, ByVal ExVeg2Cov as Single, _
ByVal ExVeg3 as String, ByVal ExVeg3Den as Single, ByVal ExVeg3Cov as Single, _
ByVal ExVeg4 as String, ByVal ExVeg4Den as Single, ByVal ExVeg4Cov as Single, _
ByVal ExVeg5 as String, ByVal ExVeg5Den as Single, ByVal ExVeg5Cov as Single, _
ByVal SoilType1 as String, ByVal SoilType1EroFac as Single, ByVal SoilType1UniCla as String, ByVal SoilType1Cov as Single, _
ByVal SoilType2 as String, ByVal SoilType2EroFac as Single, ByVal SoilType2UniCla as String, ByVal SoilType2Cov as Single, _
ByVal SoilType3 as String, ByVal SoilType3EroFac as Single, ByVal SoilType3UniCla as String, ByVal SoilType3Cov as Single, _
ByVal SoilType4 as String, ByVal SoilType4EroFac as Single, ByVal SoilType4UniCla as String, ByVal SoilType4Cov as Single, _
ByVal SoilType5 as String, ByVal SoilType5EroFac as Single, ByVal SoilType5UniCla as String, ByVal SoilType5Cov as Single, _
ByVal PreConERC as Single, ByVal PostConERC as Single, ByVal ExAreasofErosion as String, ByVal RecWaters as String, _
ByVal ExStormSewerSys as String, ByVal NatDrainWays as String, ByVal TempPlantLoc as String, ByVal PostConSWMC as String) as integer
Dim SQL As String = "UPDATE tblSWPPPBookInfo SET JobName = '" & JobName & "', City = '" & City & "', " & _
"State = '" & ST & "', County = '" & County & "', Date = '" & DT & "', " & _
"PermitNum = '" & PermitNum & "', ProjManName = '" & ProjManName & "', Title = '" & Title & "', " & _
"Inspector = '" & Inspector & "', InspQual = '" & InspQual & "', TypeofWork = '" & TypeofWork & "', DescriptionofActivity = '" & DescriptionofActivity & "', " & _
"Act1 = '" & Act1 & "', Act1StartDate = '" & Act1StartDate & "', Act1EndDate = '" & Act1EndDate & "', " & _
"Act2 = '" & Act2 & "', Act2StartDate = '" & Act2StartDate & "', Act2EndDate = '" & Act2EndDate & "', " & _
"Act3 = '" & Act3 & "', Act3StartDate = '" & Act3StartDate & "', Act3EndDate = '" & Act3EndDate & "', " & _
"Act4 = '" & Act4 & "', Act4StartDate = '" & Act4StartDate & "', Act4EndDate = '" & Act4EndDate & "', " & _
"Act5 = '" & Act5 & "', Act5StartDate = '" & Act5StartDate & "', Act5EndDate = '" & Act5EndDate & "', " & _
"Act6 = '" & Act6 & "', Act6StartDate = '" & Act6StartDate & "', Act6EndDate = '" & Act6EndDate & "', " & _
"Act7 = '" & Act7 & "', Act7StartDate = '" & Act7StartDate & "', Act7EndDate = '" & Act7EndDate & "', " & _
"Act8 = '" & Act8 & "', Act8StartDate = '" & Act8StartDate & "', Act8EndDate = '" & Act8EndDate & "', " & _
"TotalArea = " & TotalArea & ", AreatobeDisturbed = " & AreatobeDisturbed & ", AreaOffSite = " & AreaOffSite & ", " & _
"ExVeg1 = '" & ExVeg1 & "', ExVeg1Den = " & ExVeg1Den & ", ExVeg1Cov = " & ExVeg1Cov & ", " & _
"ExVeg2 = '" & ExVeg2 & "', ExVeg2Den = " & ExVeg2Den & ", ExVeg2Cov = " & ExVeg2Cov & ", " & _
"ExVeg3 = '" & ExVeg3 & "', ExVeg3Den = " & ExVeg3Den & ", ExVeg3Cov = " & ExVeg3Cov & ", " & _
"ExVeg4 = '" & ExVeg4 & "', ExVeg4Den = " & ExVeg4Den & ", ExVeg4Cov = " & ExVeg4Cov & ", " & _
"ExVeg5 = '" & ExVeg5 & "', ExVeg5Den = " & ExVeg5Den & ", ExVeg5Cov = " & ExVeg5Cov & ", " & _
"SoilType1 = '" & SoilType1 & "', SoilType1EroFac = " & SoilType1EroFac & ", SoilType1UniCla = '" & SoilType1UniCla & "', SoilType1Cov = " & SoilType1Cov & ", " & _
"SoilType2 = '" & SoilType2 & "', SoilType2EroFac = " & SoilType2EroFac & ", SoilType2UniCla = '" & SoilType2UniCla & "', SoilType2Cov = " & SoilType2Cov & ", " & _
"SoilType3 = '" & SoilType3 & "', SoilType3EroFac = " & SoilType3EroFac & ", SoilType3UniCla = '" & SoilType3UniCla & "', SoilType3Cov = " & SoilType3Cov & ", " & _
"SoilType4 = '" & SoilType4 & "', SoilType4EroFac = " & SoilType4EroFac & ", SoilType4UniCla = '" & SoilType4UniCla & "', SoilType4Cov = " & SoilType4Cov & ", " & _
"SoilType5 = '" & SoilType5 & "', SoilType5EroFac = " & SoilType5EroFac & ", SoilType5UniCla = '" & SoilType5UniCla & "', SoilType5Cov = " & SoilType5Cov & ", " & _
"PreConERC = " & PreConERC & ", PostConERC = " & PostConERC & ", ExAreasofErosion = '" & ExAreasofErosion & "', " & _
"RecWaters = '" & RecWaters & "', ExStormSewerSys = '" & ExStormSewerSys & "', NatDrainWays = '" & NatDrainWays & "', " & _
"TempPlantLoc = '" & TempPlantLoc & "', PostConSWMC = '" & PostConSWMC & "' " & _
"WHERE (JobName = '" & JobName & "');"
Dim dbCommand As IDbCommand = New OleDbCommand(SQL, conClsf)
Dim rowsAffected As Integer = 0
conClsf.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Catch Exc as Exception
Label1.Text = SQL & "<br /><br />"
Label1.Text += Exc.ToString()
Finally
conClsf.Close
End Try
Return rowsAffected
End Function
And the actual sub run by the click:
Sub SaveJob(sender As Object, e As EventArgs)
If SJ(txtJobName.text, txtCity.text, txtState.text, txtCounty.SelectedItem.text, txtDate.text, txtPermitNum.text, txtProjManName.text, _
txtTitle.text, txtInspector.text, txtInspQual.text, txtTypeofWork.text, txtDescriptionofActivity.text, _
txtAct1.text, txtAct1StartDate.text, txtAct1EndDate.text, txtAct2.text, txtAct2StartDate.text, txtAct2EndDate.text, _
txtAct3.text, txtAct3StartDate.text, txtAct3EndDate.text, txtAct4.text, txtAct4StartDate.text, txtAct4EndDate.text, _
txtAct5.text, txtAct5StartDate.text, txtAct5EndDate.text, txtAct6.text, txtAct6StartDate.text, txtAct6EndDate.text, _
txtAct7.text, txtAct7StartDate.text, txtAct7EndDate.text, txtAct8.text, txtAct8StartDate.text, txtAct8EndDate.text, _
txtTotalArea.text, txtAreatobeDisturbed.text, txtAreaOffSite.text, _
txtExVeg1.text, txtExVeg1Den.text, txtExVeg1Cov.text, txtExVeg2.text, txtExVeg2Den.text, txtExVeg2Cov.text, _
txtExVeg3.text, txtExVeg3Den.text, txtExVeg3Cov.text, txtExVeg4.text, txtExVeg4Den.text, txtExVeg4Cov.text, _
txtExVeg5.text, txtExVeg5Den.text, txtExVeg5Cov.text, _
txtSoilType1.text, txtSoilType1EroFac.text, txtSoilType1UniCla.text, txtSoilType1Cov.text, _
txtSoilType2.text, txtSoilType2EroFac.text, txtSoilType2UniCla.text, txtSoilType2Cov.text, _
txtSoilType3.text, txtSoilType3EroFac.text, txtSoilType3UniCla.text, txtSoilType3Cov.text, _
txtSoilType4.text, txtSoilType4EroFac.text, txtSoilType4UniCla.text, txtSoilType4Cov.text, _
txtSoilType5.text, txtSoilType5EroFac.text, txtSoilType5UniCla.text, txtSoilType5Cov.text, _
txtPreConERC.text, txtPostConERC.text, txtExAreasofErosion.text, txtRecWaters.text, txtExStormSewerSys.text, _
txtNatDrainWays.text, txtTempPlantLoc.text, txtPostConSWMC.text) > 0 Then
LookupJob(txtJobName.text)
Label1.Text = txtJobName.text & " has been updated"
Else
Label1.Text = txtJobName.text & " has NOT been updated"
End If
End Sub
There are a ton of fields, and I thought I had it formatted correctly, but obviously I didn't. Can you see the mistake?
Thanks, as always, you are a life-saver.
miranda
06-08-2005, 04:26 PM
I am guessing it is the use of the reserved word date in your table. Try enclosing the column name in square brackets in your select statement like so, [date] Then let me know how that works for you.
Dim SQL As String = "UPDATE tblSWPPPBookInfo SET JobName = '" & JobName & "', City = '" & City & "', " & _
"State = '" & ST & "', County = '" & County & "', [Date] = '" & DT & "', " & _
"PermitNum = '" & PermitNum & "', ProjManName = '" & ProjManName & "', Title = '" & Title & "', " & _
"Inspector = '" & Inspector & "', InspQual = '" & InspQual & "', TypeofWork = '" & TypeofWork & "', DescriptionofActivity = '" & DescriptionofActivity & "', " & _
"Act1 = '" & Act1 & "', Act1StartDate = '" & Act1StartDate & "', Act1EndDate = '" & Act1EndDate & "', " & _
"Act2 = '" & Act2 & "', Act2StartDate = '" & Act2StartDate & "', Act2EndDate = '" & Act2EndDate & "', " & _
"Act3 = '" & Act3 & "', Act3StartDate = '" & Act3StartDate & "', Act3EndDate = '" & Act3EndDate & "', " & _
"Act4 = '" & Act4 & "', Act4StartDate = '" & Act4StartDate & "', Act4EndDate = '" & Act4EndDate & "', " & _
"Act5 = '" & Act5 & "', Act5StartDate = '" & Act5StartDate & "', Act5EndDate = '" & Act5EndDate & "', " & _
"Act6 = '" & Act6 & "', Act6StartDate = '" & Act6StartDate & "', Act6EndDate = '" & Act6EndDate & "', " & _
"Act7 = '" & Act7 & "', Act7StartDate = '" & Act7StartDate & "', Act7EndDate = '" & Act7EndDate & "', " & _
"Act8 = '" & Act8 & "', Act8StartDate = '" & Act8StartDate & "', Act8EndDate = '" & Act8EndDate & "', " & _
"TotalArea = " & TotalArea & ", AreatobeDisturbed = " & AreatobeDisturbed & ", AreaOffSite = " & AreaOffSite & ", " & _
"ExVeg1 = '" & ExVeg1 & "', ExVeg1Den = " & ExVeg1Den & ", ExVeg1Cov = " & ExVeg1Cov & ", " & _
"ExVeg2 = '" & ExVeg2 & "', ExVeg2Den = " & ExVeg2Den & ", ExVeg2Cov = " & ExVeg2Cov & ", " & _
"ExVeg3 = '" & ExVeg3 & "', ExVeg3Den = " & ExVeg3Den & ", ExVeg3Cov = " & ExVeg3Cov & ", " & _
"ExVeg4 = '" & ExVeg4 & "', ExVeg4Den = " & ExVeg4Den & ", ExVeg4Cov = " & ExVeg4Cov & ", " & _
"ExVeg5 = '" & ExVeg5 & "', ExVeg5Den = " & ExVeg5Den & ", ExVeg5Cov = " & ExVeg5Cov & ", " & _
"SoilType1 = '" & SoilType1 & "', SoilType1EroFac = " & SoilType1EroFac & ", SoilType1UniCla = '" & SoilType1UniCla & "', SoilType1Cov = " & SoilType1Cov & ", " & _
"SoilType2 = '" & SoilType2 & "', SoilType2EroFac = " & SoilType2EroFac & ", SoilType2UniCla = '" & SoilType2UniCla & "', SoilType2Cov = " & SoilType2Cov & ", " & _
"SoilType3 = '" & SoilType3 & "', SoilType3EroFac = " & SoilType3EroFac & ", SoilType3UniCla = '" & SoilType3UniCla & "', SoilType3Cov = " & SoilType3Cov & ", " & _
"SoilType4 = '" & SoilType4 & "', SoilType4EroFac = " & SoilType4EroFac & ", SoilType4UniCla = '" & SoilType4UniCla & "', SoilType4Cov = " & SoilType4Cov & ", " & _
"SoilType5 = '" & SoilType5 & "', SoilType5EroFac = " & SoilType5EroFac & ", SoilType5UniCla = '" & SoilType5UniCla & "', SoilType5Cov = " & SoilType5Cov & ", " & _
"PreConERC = " & PreConERC & ", PostConERC = " & PostConERC & ", ExAreasofErosion = '" & ExAreasofErosion & "', " & _
"RecWaters = '" & RecWaters & "', ExStormSewerSys = '" & ExStormSewerSys & "', NatDrainWays = '" & NatDrainWays & "', " & _
"TempPlantLoc = '" & TempPlantLoc & "', PostConSWMC = '" & PostConSWMC & "' " & _
"WHERE (JobName = '" & JobName & "');"
BTW when you are filling in a form and you have a dropdownlist that you want to selct the value of the data in your database you would use
if ((rdrMbrs.Item("County")) is System.DBNull.Value) then
'txtCounty.SelectedIndex = 0 'sets the list to the 1st row
else
'using the GetString() method of the DataReader assuming county is the 4th column in the database
'txtCounty.SelectedIndex = txtCounty.Items.IndexOf(txtCounty.Items.FindByText(rdrMbrs.GetString(3)))
txtCounty.SelectedIndex = txtCounty.Items.IndexOf(txtCounty.Items.FindByText(rdrMbrs.Item("County")))
end if
miranda
06-08-2005, 08:54 PM
Did you see this part of the error?
Stack Trace:
[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String Value, NumberFormatInfo NumberFormat) +164
Microsoft.VisualBasic.CompilerServices.SingleType.FromString(String Value, NumberFormatInfo NumberFormat) +84
[InvalidCastException: Cast from string "" to type 'Single' is not valid.]
Microsoft.VisualBasic.CompilerServices.SingleType.FromString(String Value, NumberFormatInfo NumberFormat) +179
Microsoft.VisualBasic.CompilerServices.SingleType.FromString(String Value) +7
ASP.swppp_aspx.SaveJob(Object sender, EventArgs e) in C:\Inetpub\wwwroot\swppp.aspx:541
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1281
You have multiple cases where you are trying to do this. Each of the following requires a value and cannot be left blank (txtExVeg1Den.text, txtExVeg1Cov.text, txtExVeg2Den.text, txtExVeg2Cov.text, txtExVeg3Den.text, txtExVeg3Cov.text, txtExVeg4Den.text, txtExVeg4Cov.text, txtExVeg5Den.text, txtExVeg5Cov.text, txtSoilType1EroFac.text, txtSoilType1Cov.text, txtSoilType2EroFac.text, txtSoilType2Cov.text, txtSoilType3EroFac.text, txtSoilType3Cov.text, txtSoilType4EroFac.text, txtSoilType4Cov.text, txtSoilType5EroFac.text)
You could change all of the datatypes in the database from single to text, then you will have to alter the insert statement. Or if you leave the database structure as is you could enter a value maybe a 0(zero) into each of the empty number fields.
Without changing the datatypes in the database the correct way to do it without adding a zero is to look at the fields and build your your function call and your SQL UPDATE statement according to which fields are used.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.