sithman17
asked on
Inserting a checkbox value into a SQL table via ASP.NET form.
Hello experts,
Does anyone know of a way to store the value of a checkbox on an ASP page in a SQL table as either a true or false value? I know how to retrieve the info from SQL, but not insert it. Currently the method I am using sets the value to true regardless of what is checked on the form.
Thanks.
Here is the code I am using.
Imports System.Data.SqlClient
Imports GISTableAdapters
Imports System.Net.Mail
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtDateIn.Text = Today
txtID.Text = User.Identity.Name
End Sub
Protected Sub ddlRush_SelectedIndexChang ed(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRush.SelectedIndexChang ed
If ddlRush.SelectedIndex = 2 Then
txtDateBy.Text = Today.AddDays(1)
Else
txtDateBy.Text = Today.AddDays(4)
End If
End Sub
Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Dim NewCase As New tblRequests1TableAdapter
Dim requestno As Integer
Dim m As New MailMessage
If txtDateBy.Text = "" Then
lblErrMsg.Text = "This is a required field in the form of mm/dd/yyyy."
lblErrMsg.Visible = True
lblError1.Visible = True
txtDateBy.Focus()
Exit Sub
Else
lblError1.Visible = False
lblErrMsg.Visible = False
End If
'Check to make sure there is a project name associated with the field less
'than 75 characters
If txtProjName.Text = "" Then
lblErrMsg.Visible = True
lblErrMsg.Text = "This is a required field."
lblError2.Visible = True
txtProjName.Focus()
Exit Sub
Else
lblError2.Visible = False
lblErrMsg.Visible = False
End If
'Check to make sure if there are hours assigned to the request
If txtHours.Text = "" Then
lblErrMsg.Visible = True
lblErrMsg.Text = "You must assign hours for this request."
txtHours.Focus()
Else
lblErrMsg.Visible = False
End If
'check to see the values of the # of copies and correct so value isnt Null
If txtcpySite.Text = "" Then
txtcpySite.Text = "0"
End If
If txtcpySoils.Text = "" Then
txtcpySoils.Text = "0"
End If
If txtcpyCNDDB.Text = "" Then
txtcpyCNDDB.Text = "0"
End If
If txtcpyWet.Text = "" Then
txtcpyWet.Text = "0"
End If
If txtcpyPropMap.Text = "" Then
txtcpyPropMap.Text = "0"
End If
If txtcpyBioConst.Text = "" Then
txtcpyBioConst.Text = "0"
End If
If txtcpyBMP.Text = "" Then
txtcpyBMP.Text = "0"
End If
If txtcpyFlight.Text = "" Then
txtcpyFlight.Text = "0"
End If
If txtcpyHistoric.Text = "" Then
txtcpyHistoric.Text = "0"
End If
requestno = Convert.ToInt32(NewCase.In sertNewReq uest(txtDa teIn.Text, txtDateBy.Text, _
ddlRush.SelectedValue, ddlOffice.SelectedValue, txtProjName.Text, txtCty.Text, _
txtDeltek.Text, txtHours.Text, ddlPM.SelectedIndex, ddlPoC.SelectedIndex, _
ddlReqBy.SelectedIndex, txtID.Text, "New", ddlBioRes.SelectedValue.To String, _
ddlBioConst.SelectedValue. ToString, ddlWetlnd.SelectedValue.To String, _
ddlArborist.SelectedValue. ToString, ddlMonitoring.SelectedValu e.ToString , _
ddlOther.SelectedValue.ToS tring, ddlPCN.SelectedValue.ToStr ing, _
ddlPublic.SelectedValue.To String, ddlSec7.SelectedValue.ToSt ring, _
ddlOnsiteAA.SelectedValue. ToString, ddlOffsiteAA.SelectedValue .ToString, _
ddlPMP.SelectedValue.ToStr ing, ddlCEQA.SelectedValue.ToSt ring, _
ddlSWPPP.SelectedValue.ToS tring, ddlWQC.SelectedValue.ToStr ing, _
ddlSAA.SelectedValue.ToStr ing, txtcpySite.Text, txtcpySoils.Text, txtcpyCNDDB.Text, _
txtcpyWet.Text, txtcpyPropMap.Text, txtcpyBioConst.Text, txtcpyBMP.Text, _
txtcpyFlight.Text, txtcpyHistoric.Text, ddlprnSite.SelectedValue.T oString, _
ddlprnSoils.SelectedValue. ToString, ddlprnCNDDB.SelectedValue. ToString, _
ddlprnWetlnd.SelectedValue .ToString, ddlprnPropMap.SelectedValu e.ToString , _
ddlprnBioConst.SelectedVal ue.ToStrin g, ddlprnBMP.SelectedValue.To String, _
ddlprnFlight.SelectedValue .ToString, ddlprnHistoric.SelectedVal ue.ToStrin g, _
ddltypeSite.SelectedValue. ToString, ddltypeSoils.SelectedValue .ToString, _
ddltypeCNDDB.SelectedValue .ToString, ddltypeWetlnd.SelectedValu e.ToString , _
ddltypePropMap.SelectedVal ue.ToStrin g, ddltypeBioConst.SelectedVa lue.ToStri ng, _
ddltypeBMP.SelectedValue.T oString, ddltypeFlight.SelectedValu e.ToString , _
ddltypeHistoric.SelectedVa lue.ToStri ng, chkAerialField.Checked.Get Type, _
chkCAD.Checked.GetType, chkGPSBckgrnd.Checked.GetT ype, chkDataCD.Checked.GetType, _
chkDigi2clnt.Checked.GetTy pe, chkOtherfield.Checked.GetT ype, chkDigCad.Checked.GetType, _
chkParcel.Checked.GetType, chkAerial.Checked.GetType, chkGPS.Checked.GetType, _
chkOther.Checked.GetType, txtNotes.Text))
Label5.Text = "Request # " & requestno & " has been entered successfully. You will receive an email shortly."
If ddlRush.SelectedIndex = 2 Then
'Add the sender, and recepients. CC the user.
m.From = New MailAddress("GIS@foothill. com")
m.To.Add("jsanchez@Foothil l.com")
'Add the subject to the email so it gets by the SPAM filter.
m.Subject = "Request # for " & txtProjName.Text & " - RUSH."
m.Body = "The request from " & txtEmpName.Text & " is due " & txtDateBy.Text & " and is expected to take " & txtHours.Text & "."
'Make sure the body of the email is HTML
m.IsBodyHtml = True
m.Priority = MailPriority.High
'Send the message
Dim smtp As New SmtpClient("192.168.254.13 ")
smtp.Send(m)
cmdSubmit.PostBackUrl = "~/Default.aspx"
ElseIf ddlRush.SelectedIndex = 1 Then
With m
'Add the sender, and recepients. CC the user.
.From = New MailAddress("GISAdmin@foot hill.com")
.To.Add("jsanchez@foothill .com")
'Add the subject to the email so it gets by the SPAM filter.
.Subject = "Request # has been submitted"
.Body = "The request from " & txtEmpName.Text & " is due " & txtDateBy.Text & " and is expected to take " & txtHours.Text & "."
'Make sure the body of the email is HTML
.IsBodyHtml = True
.Priority = MailPriority.Normal
'Send the message
Dim smtp As New SmtpClient("192.168.254.13 ")
smtp.Send(m)
cmdSubmit.PostBackUrl = "~/Default.aspx"
End With
End If
End Sub
Protected Sub ddlReqBy_SelectedIndexChan ged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlReqBy.SelectedIndexChan ged
Dim email As New taPM
txtReqEmail.Text = email.GetPM(ddlReqBy.Selec tedIndex). pmEmail
txtEmpName.Text = email.GetPM(ddlReqBy.Selec tedIndex). pmName
End Sub
End Class
Does anyone know of a way to store the value of a checkbox on an ASP page in a SQL table as either a true or false value? I know how to retrieve the info from SQL, but not insert it. Currently the method I am using sets the value to true regardless of what is checked on the form.
Thanks.
Here is the code I am using.
Imports System.Data.SqlClient
Imports GISTableAdapters
Imports System.Net.Mail
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtDateIn.Text = Today
txtID.Text = User.Identity.Name
End Sub
Protected Sub ddlRush_SelectedIndexChang
If ddlRush.SelectedIndex = 2 Then
txtDateBy.Text = Today.AddDays(1)
Else
txtDateBy.Text = Today.AddDays(4)
End If
End Sub
Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Dim NewCase As New tblRequests1TableAdapter
Dim requestno As Integer
Dim m As New MailMessage
If txtDateBy.Text = "" Then
lblErrMsg.Text = "This is a required field in the form of mm/dd/yyyy."
lblErrMsg.Visible = True
lblError1.Visible = True
txtDateBy.Focus()
Exit Sub
Else
lblError1.Visible = False
lblErrMsg.Visible = False
End If
'Check to make sure there is a project name associated with the field less
'than 75 characters
If txtProjName.Text = "" Then
lblErrMsg.Visible = True
lblErrMsg.Text = "This is a required field."
lblError2.Visible = True
txtProjName.Focus()
Exit Sub
Else
lblError2.Visible = False
lblErrMsg.Visible = False
End If
'Check to make sure if there are hours assigned to the request
If txtHours.Text = "" Then
lblErrMsg.Visible = True
lblErrMsg.Text = "You must assign hours for this request."
txtHours.Focus()
Else
lblErrMsg.Visible = False
End If
'check to see the values of the # of copies and correct so value isnt Null
If txtcpySite.Text = "" Then
txtcpySite.Text = "0"
End If
If txtcpySoils.Text = "" Then
txtcpySoils.Text = "0"
End If
If txtcpyCNDDB.Text = "" Then
txtcpyCNDDB.Text = "0"
End If
If txtcpyWet.Text = "" Then
txtcpyWet.Text = "0"
End If
If txtcpyPropMap.Text = "" Then
txtcpyPropMap.Text = "0"
End If
If txtcpyBioConst.Text = "" Then
txtcpyBioConst.Text = "0"
End If
If txtcpyBMP.Text = "" Then
txtcpyBMP.Text = "0"
End If
If txtcpyFlight.Text = "" Then
txtcpyFlight.Text = "0"
End If
If txtcpyHistoric.Text = "" Then
txtcpyHistoric.Text = "0"
End If
requestno = Convert.ToInt32(NewCase.In
ddlRush.SelectedValue, ddlOffice.SelectedValue, txtProjName.Text, txtCty.Text, _
txtDeltek.Text, txtHours.Text, ddlPM.SelectedIndex, ddlPoC.SelectedIndex, _
ddlReqBy.SelectedIndex, txtID.Text, "New", ddlBioRes.SelectedValue.To
ddlBioConst.SelectedValue.
ddlArborist.SelectedValue.
ddlOther.SelectedValue.ToS
ddlPublic.SelectedValue.To
ddlOnsiteAA.SelectedValue.
ddlPMP.SelectedValue.ToStr
ddlSWPPP.SelectedValue.ToS
ddlSAA.SelectedValue.ToStr
txtcpyWet.Text, txtcpyPropMap.Text, txtcpyBioConst.Text, txtcpyBMP.Text, _
txtcpyFlight.Text, txtcpyHistoric.Text, ddlprnSite.SelectedValue.T
ddlprnSoils.SelectedValue.
ddlprnWetlnd.SelectedValue
ddlprnBioConst.SelectedVal
ddlprnFlight.SelectedValue
ddltypeSite.SelectedValue.
ddltypeCNDDB.SelectedValue
ddltypePropMap.SelectedVal
ddltypeBMP.SelectedValue.T
ddltypeHistoric.SelectedVa
chkCAD.Checked.GetType, chkGPSBckgrnd.Checked.GetT
chkDigi2clnt.Checked.GetTy
chkParcel.Checked.GetType,
chkOther.Checked.GetType, txtNotes.Text))
Label5.Text = "Request # " & requestno & " has been entered successfully. You will receive an email shortly."
If ddlRush.SelectedIndex = 2 Then
'Add the sender, and recepients. CC the user.
m.From = New MailAddress("GIS@foothill.
m.To.Add("jsanchez@Foothil
'Add the subject to the email so it gets by the SPAM filter.
m.Subject = "Request # for " & txtProjName.Text & " - RUSH."
m.Body = "The request from " & txtEmpName.Text & " is due " & txtDateBy.Text & " and is expected to take " & txtHours.Text & "."
'Make sure the body of the email is HTML
m.IsBodyHtml = True
m.Priority = MailPriority.High
'Send the message
Dim smtp As New SmtpClient("192.168.254.13
smtp.Send(m)
cmdSubmit.PostBackUrl = "~/Default.aspx"
ElseIf ddlRush.SelectedIndex = 1 Then
With m
'Add the sender, and recepients. CC the user.
.From = New MailAddress("GISAdmin@foot
.To.Add("jsanchez@foothill
'Add the subject to the email so it gets by the SPAM filter.
.Subject = "Request # has been submitted"
.Body = "The request from " & txtEmpName.Text & " is due " & txtDateBy.Text & " and is expected to take " & txtHours.Text & "."
'Make sure the body of the email is HTML
.IsBodyHtml = True
.Priority = MailPriority.Normal
'Send the message
Dim smtp As New SmtpClient("192.168.254.13
smtp.Send(m)
cmdSubmit.PostBackUrl = "~/Default.aspx"
End With
End If
End Sub
Protected Sub ddlReqBy_SelectedIndexChan
Dim email As New taPM
txtReqEmail.Text = email.GetPM(ddlReqBy.Selec
txtEmpName.Text = email.GetPM(ddlReqBy.Selec
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.