473,383 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 1269
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

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

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
1
by: Chris Jackson | last post by:
I'm a novice Access user and am not sure how to solve the following problem. Any help with the following would be greatly appreciated! I have two tables with identical structures, the first holds...
2
by: Ray Holtz | last post by:
I have a form that shows a single record based on a query criteria. When I click a button it is set to use an append query to copy that record to a separate table, then deletes the record from the...
3
by: MLH | last post by:
I have a form, bound to a query. Its RecordSource property is a query named frmEnterLienAmounts. The form has a few bound controls and some unbound controls. The unbound controls are calculated...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
4
by: Winshent | last post by:
I am having problems with adding items to my shopping cart. The problem occures when adding items that already exists in the cart. When a user adds to cart, they are automatically redirected to...
1
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to...
5
by: Hexman | last post by:
I've come up with an error which the solution eludes me. I get the error: >An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in HRTest.exe > >Additional...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
4
by: aaronyoung | last post by:
I have created custom navigation buttons and Record Number indicators on several forms that are used to review and update records based on a query. My On Current event to update the "Record X of...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.