469,607 Members | 2,048 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,607 developers. It's quick & easy.

Updating a record - asp.net with vb.net

27
I'm trying to update a record using "System.Data.SqlClient" in asp.net.

Here is my code:

[HTML]<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>
<Script Language="VB" Runat="Server">

dim objCmd As SqlCommand
dim objRdr As SqlDataReader
dim strCmd As String


Sub Page_Load()

CheckActive()
LogActivity()

sysMenu = true

BindData()

end sub

Sub BindData()

dim dsn As String = ConfigurationSettings.AppSettings("SystemConnectio nNew")

dim objConn as New SqlConnection(dsn)

objCmd = New SqlCommand("SELECT * FROM tbl_ACCO_EU_Contacts WHERE EndUserID=" & Request.QueryString("id"), objConn )

objConn.open()

objRdr = objCmd.ExecuteReader()
'dbcontacts.DataSource = objRdr

'dbcontacts.DataBind()

While objRdr.Read()

If not isDbNull(objRdr.Item("Title")) Then
textTitle.Text = objRdr.Item("Title")
End If

If not isDbNull(objRdr.Item("FirstName")) Then
textFirstName.Text = objRdr.Item("FirstName")
End If

If not isDbNull(objRdr.Item("LastName")) Then
textLastName.Text = objRdr.Item("LastName")
End If

If not isDbNull(objRdr.Item("CompanyName")) Then
textCompanyName.Text = objRdr.Item("CompanyName")
End If

If not isDbNull(objRdr.Item("CompanyPosition")) Then
textCompanyPosition.Text = objRdr.Item("CompanyPosition")
End If

If not isDbNull(objRdr.Item("CompanyAddress1")) Then
textCompanyAddress1.Text = objRdr.Item("CompanyAddress1")
End If

If not isDbNull(objRdr.Item("CompanyAddress2")) Then
textCompanyAddress2.Text = objRdr.Item("CompanyAddress2")
End If

If not isDbNull(objRdr.Item("CompanyAddress3")) Then
textCompanyAddress3.Text = objRdr.Item("CompanyAddress3")
End If

If not isDbNull(objRdr.Item("CompanyAddress4")) Then
textCompanyAddress4.Text = objRdr.Item("CompanyAddress4")
End If

If not isDbNull(objRdr.Item("CompanyTown")) Then
textCompanyTown.Text = objRdr.Item("CompanyTown")
End If

If not isDbNull(objRdr.Item("CompanyCounty")) Then
textCompanyCounty.Text = objRdr.Item("CompanyCounty")
End If

If not isDbNull(objRdr.Item("CompanyPostcode")) Then
textCompanyPostcode.Text = objRdr.Item("CompanyPostcode")
End If

If not isDbNull(objRdr.Item("CompanyCountry")) Then
textCompanyCountry.Text = objRdr.Item("CompanyCountry")
End If

If not isDbNull(objRdr.Item("CompanyEMailAddress")) Then
textCompanyEMailAddress.Text = objRdr.Item("CompanyEMailAddress")
End If

If not isDbNull(objRdr.Item("CompanyTelephone")) Then
textCompanyTelephone.Text = objRdr.Item("CompanyTelephone")
End If

If not isDbNull(objRdr.Item("CompanyFax")) Then
textTitle.Text = objRdr.Item("CompanyFax")
End If

If not isDbNull(objRdr.Item("CompanyDirectDial")) Then
textCompanyDirectDial.Text = objRdr.Item("CompanyDirectDial")
End If

If not isDbNull(objRdr.Item("CompanyWebAddress")) Then
textCompanyWebAddress.Text = objRdr.Item("CompanyWebAddress")
End If

If not isDbNull(objRdr.Item("CompanySIC")) Then
textCompanySIC.Text = objRdr.Item("CompanySIC")
End If

If not isDbNull(objRdr.Item("CompanySize")) Then
textCompanySize.Text = objRdr.Item("CompanySize")
End If

If not isDbNull(objRdr.Item("PersonalAddress1")) Then
textPersonalAddress1.Text = objRdr.Item("PersonalAddress1")
End If

If not isDbNull(objRdr.Item("PersonalAddress2")) Then
textPersonalAddress2.Text = objRdr.Item("PersonalAddress2")
End If

If not isDbNull(objRdr.Item("PersonalAddress3")) Then
textPersonalAddress3.Text = objRdr.Item("PersonalAddress3")
End If

If not isDbNull(objRdr.Item("PersonalAddress4")) Then
textPersonalAddress4.Text = objRdr.Item("PersonalAddress4")
End If

If not isDbNull(objRdr.Item("PersonalTown")) Then
textPersonalTown.Text = objRdr.Item("PersonalTown")
End If

If not isDbNull(objRdr.Item("PersonalCounty")) Then
textPersonalCounty.Text = objRdr.Item("PersonalCounty")
End If

If not isDbNull(objRdr.Item("PersonalPostCode")) Then
textPersonalPostCode.Text = objRdr.Item("PersonalPostCode")
End If

If not isDbNull(objRdr.Item("PersonalCountry")) Then
textPersonalCountry.Text = objRdr.Item("PersonalCountry")
End If

If not isDbNull(objRdr.Item("EndUserID")) Then
textEndUserID.Text = objRdr.Item("EndUserID")
End If

End While

objRdr.Close()

objConn.Close()

btnUpdate.Enabled = True

End Sub

sub UpdateRec(s As Object, e As EventArgs)

dim dsn As String = ConfigurationSettings.AppSettings("SystemConnectio nNew")

dim objConn as New SqlConnection(dsn)

strCmd = "UPDATE tbl_ACCO_EU_Contacts SET Title=@Title, FirstName=@FirstName, LastName=@LastName, CompanyPosition=@CompanyPosition, CompanyName=@CompanyName, CompanyAddress1=@CompanyAddress1, CompanyAddress2=@CompanyAddress2, CompanyAddress3=@CompanyAddress3, CompanyAddress4=@CompanyAddress4, CompanyTown=@CompanyTown, CompanyCounty=@CompanyCounty, CompanyPostcode=@CompanyPostcode, CompanyEMailAddress=@CompanyEMailAddress, CompanyTelephone=@CompanyTelephone, CompanyFax=@CompanyFax, CompanyDirectDial=@CompanyDirectDial, CompanyWebAddress=@CompanyWebAddress, CompanySIC=@CompanySIC, CompanySize=@CompanySize, PersonalAddress1=@PersonalAddress1, PersonalAddress3=@PersonalAddress3, PersonalAddress4=@PersonalAddress4, PersonalTown=@PersonalTown, PersonalCounty=@PersonalCounty, PersonalPostCode=@PersonalPostCode, PersonalCountry=@PersonalCountry WHERE EndUserID=@EndUserID"

Dim objCmd As New SqlCommand(strCmd, objConn)

objCmd.Parameters.Add("@Title", textTitle.Text)
objCmd.Parameters.Add("@FirstName", textFirstName.Text)
objCmd.Parameters.Add("@LastName", textLastName.Text)
objCmd.Parameters.Add("@CompanyPosition", textCompanyPosition.Text)
objCmd.Parameters.Add("@CompanyName", textCompanyName.Text)
objCmd.Parameters.Add("@CompanyAddress1", textCompanyAddress1.Text)
objCmd.Parameters.Add("@CompanyAddress2", textCompanyAddress2.Text)
objCmd.Parameters.Add("@CompanyAddress3", textCompanyAddress3.Text)
objCmd.Parameters.Add("@CompanyAddress4", textCompanyAddress4.Text)
objCmd.Parameters.Add("@CompanyTown", textCompanyTown.Text)
objCmd.Parameters.Add("@CompanyCounty", textCompanyCounty.Text)
objCmd.Parameters.Add("@CompanyPostcode", textCompanyPostcode.Text)
objCmd.Parameters.Add("@CompanyEMailAddress", textCompanyEMailAddress.Text)
objCmd.Parameters.Add("@CompanyTelephone", textCompanyTelephone.Text)
objCmd.Parameters.Add("@CompanyFax", textCompanyFax.Text)
objCmd.Parameters.Add("@CompanyDirectDial", textCompanyDirectDial.Text)
objCmd.Parameters.Add("@CompanyWebAddress", textCompanyWebAddress.Text)
objCmd.Parameters.Add("@CompanySIC", textCompanySIC.Text)
objCmd.Parameters.Add("@CompanySize", textCompanySize.Text)
objCmd.Parameters.Add("@PersonalAddress1", textPersonalAddress1.Text)
objCmd.Parameters.Add("@PersonalAddress2", textPersonalAddress2.Text)
objCmd.Parameters.Add("@PersonalAddress3", textPersonalAddress3.Text)
objCmd.Parameters.Add("@PersonalAddress4", textPersonalAddress4.Text)
objCmd.Parameters.Add("@PersonalTown", textPersonalTown.Text)
objCmd.Parameters.Add("@PersonalCounty", textPersonalCounty.Text)
objCmd.Parameters.Add("@PersonalPostCode", textPersonalPostCode.Text)
objCmd.Parameters.Add("@PersonalCountry", textPersonalCountry.Text)
objCmd.Parameters.Add("@EndUserID", textEndUserID.Text)

objConn.open()

objCmd.ExecuteNonQuery()

objConn.close()

response.Redirect("record_srch.aspx")

end sub[/HTML]

I'm not getting any error message back when the form is submitted, but the record is not updating.

Any ideas?

Cheers

Adz
Sep 4 '07 #1
3 1160
kenobewan
4,871 Expert 4TB
Is the response.redirect working?

btw - did you choose that color?
Sep 4 '07 #2
adz1809
27
Is the response.redirect working?

btw - did you choose that color?

Yep, the redirect works fine and no I didn't choose the colour, it did that all by itself.

Does the redirect have an effect on the update?
Sep 4 '07 #3
kenobewan
4,871 Expert 4TB
No but it shows that that updaterec was called but your update statement didn't work. Most likely reason is that you ended up with no EndUserID. HTH.
Sep 5 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Jason | last post: by
1 post views Thread by Chris Jackson | last post: by
2 posts views Thread by Ray Holtz | last post: by
5 posts views Thread by junglist | last post: by
4 posts views Thread by Winshent | last post: by
1 post views Thread by Spock | last post: by
33 posts views Thread by bill | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.