annbransom
08-10-2006, 01:08 AM
HELP!!! I am building a website which has a lot of database functionality on it. All of my select statements work and my insert statements. But for some reason I am having trouble getting my update statements to work. I've tried them on several different pages and so the common denominator is me, I just don't know what I am doing wrong. Take the sub below for example. Some of the information being passed in the Update statement comes from variables I've declared. Some of it comes straight from the text boxes on my form. If you look at "City" however, I give it an explicit value in the statement. When I click the update button, the only thing that updates is the city!!! Help! Let me know if seeing any other parts of the code would be helpful.
Thanks,
Ann
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim sqlConn As SqlConnection = New SqlConnection(dbConn)
Dim sqlCmd As SqlCommand = New System.Data.SqlClient.SqlCommand()
Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter
Dim dt As New DataTable
Dim FileNamePartOne As String
FileNamePartOne = LastNameTextBox.Text & "_"
Dim FilePathConstant As String = Server.MapPath("Pics\")
Dim file As Array = Split(FileUpload1.FileName, "\")
Dim fi As New FileInfo("\Pics\" & FileNamePartOne & file(file.Length - 1))
Dim FileN As String
'fi.ToString = the path for db
If fi.Exists Then
fi.Delete()
End If
If FileUpload1.FileName <> "" Then
FileUpload1.PostedFile.SaveAs(FilePathConstant & FileNamePartOne & file(file.Length - 1))
FileN = "Pics\" & FileNamePartOne & file(file.Length - 1)
Else
FileN = ""
End If
Dim FName As String
FName = FirstNameTextBox.Text
FName = Replace(FName, "'", "''")
Dim LName As String
LName = LastNameTextBox.Text
LName = Replace(LName, "'", "''")
Dim Add1 As String
Add1 = AddressLine1TextBox.Text
Add1 = Replace(Add1, "'", "''")
Dim Add2 As String
Add2 = AddressLine2TextBox.Text
Add2 = Replace(Add2, "'", "''")
Dim City As String
City = CityTextBox.Text
City = Replace(City, "'", "''")
Dim Occ As String
Occ = OccupationTextBox.Text
Occ = Replace(Occ, "'", "''")
Dim SFName As String
SFName = SpouseFirstNameTextBox.Text
SFName = Replace(SFName, "'", "''")
Dim SLName As String
SLName = SpouseLastNameTextBox.Text
SLName = Replace(SLName, "'", "''")
With sqlCmd
.CommandType = CommandType.Text
.Connection = sqlConn
.CommandText = "UPDATE KidsKlub_Members SET FirstName= '" & FName & "', LastName = '" & LName & "', Email = '" & EmailTextBox.Text & "', AddressLine1 = '" & Add1 & "', AddressLine2 = '" & Add2 & "', City = 'Louisville', State = '" & StateTextBox.Text & "', ZipCode = '" & ZipCodeTextBox.Text & "', PhoneNum1 = '" & PhoneNum1TextBox.Text & "', PhoneNum2 = '" & PhoneNum2TextBox.Text & "', PhoneNum3 = '" & PhoneNum3TextBox.Text & "', Occupation = '" & Occ & "', Birthday = '" & BirthdayTextBox.Text & "', SpouseFirstName = '" & SFName & "', SpouseLastName = '" & SLName & "', SpouseBirthday = '" & SpouseBirthdayTextBox.Text & "', FamilyPicURL = '" & FileN & "' WHERE MemberID = " & CInt(Session("PassID"))
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
End With
loaddata()
End Sub
Thanks,
Ann
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim sqlConn As SqlConnection = New SqlConnection(dbConn)
Dim sqlCmd As SqlCommand = New System.Data.SqlClient.SqlCommand()
Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter
Dim dt As New DataTable
Dim FileNamePartOne As String
FileNamePartOne = LastNameTextBox.Text & "_"
Dim FilePathConstant As String = Server.MapPath("Pics\")
Dim file As Array = Split(FileUpload1.FileName, "\")
Dim fi As New FileInfo("\Pics\" & FileNamePartOne & file(file.Length - 1))
Dim FileN As String
'fi.ToString = the path for db
If fi.Exists Then
fi.Delete()
End If
If FileUpload1.FileName <> "" Then
FileUpload1.PostedFile.SaveAs(FilePathConstant & FileNamePartOne & file(file.Length - 1))
FileN = "Pics\" & FileNamePartOne & file(file.Length - 1)
Else
FileN = ""
End If
Dim FName As String
FName = FirstNameTextBox.Text
FName = Replace(FName, "'", "''")
Dim LName As String
LName = LastNameTextBox.Text
LName = Replace(LName, "'", "''")
Dim Add1 As String
Add1 = AddressLine1TextBox.Text
Add1 = Replace(Add1, "'", "''")
Dim Add2 As String
Add2 = AddressLine2TextBox.Text
Add2 = Replace(Add2, "'", "''")
Dim City As String
City = CityTextBox.Text
City = Replace(City, "'", "''")
Dim Occ As String
Occ = OccupationTextBox.Text
Occ = Replace(Occ, "'", "''")
Dim SFName As String
SFName = SpouseFirstNameTextBox.Text
SFName = Replace(SFName, "'", "''")
Dim SLName As String
SLName = SpouseLastNameTextBox.Text
SLName = Replace(SLName, "'", "''")
With sqlCmd
.CommandType = CommandType.Text
.Connection = sqlConn
.CommandText = "UPDATE KidsKlub_Members SET FirstName= '" & FName & "', LastName = '" & LName & "', Email = '" & EmailTextBox.Text & "', AddressLine1 = '" & Add1 & "', AddressLine2 = '" & Add2 & "', City = 'Louisville', State = '" & StateTextBox.Text & "', ZipCode = '" & ZipCodeTextBox.Text & "', PhoneNum1 = '" & PhoneNum1TextBox.Text & "', PhoneNum2 = '" & PhoneNum2TextBox.Text & "', PhoneNum3 = '" & PhoneNum3TextBox.Text & "', Occupation = '" & Occ & "', Birthday = '" & BirthdayTextBox.Text & "', SpouseFirstName = '" & SFName & "', SpouseLastName = '" & SLName & "', SpouseBirthday = '" & SpouseBirthdayTextBox.Text & "', FamilyPicURL = '" & FileN & "' WHERE MemberID = " & CInt(Session("PassID"))
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
End With
loaddata()
End Sub