473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UPDATE a SQL database

I'm trying to update a SQL2000 database through a web form. Visual Basic.Net
2003,This is an abbreviated chunk of code.

The primary key field in the table is HospitalProvide rNumber. It is an
NVarChar (10). Some of the Hospital Provider Numbers begin with zero
(020026).

The table won't update with the WHERE clause. In my attempts to find what's
working and not, I've easily filled the Hospital Name column with the name of
one hospital by removing the WHERE so I know the update works.

I have a similar web form in which the HospitalSystemI D is a long integer
(autonumber) and similar code to update that table works as expected.

I'm guessing the difference is a long integer in the one that works, an
NVarChar in the one that doesn't

Any suggestions?

Private Sub btnSaveHospital _Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnSaveHospital .Click
Dim strConn As String
strConn = "integrated security=SSPI;d ata source=Aho1;per sist security
info=False;init ial catalog=HRRC"
Dim myConnection As New SqlClient.SqlCo nnection(strCon n)
Dim SqlCommandUpdat eHospital As New SqlClient.SqlCo mmand
SqlCommandUpdat eHospital.Conne ction = myConnection

SqlCommandUpdat eHospital.Param eters.Add(New
SqlClient.SqlPa rameter("@Provi derID", txtProviderNumb er.Text))
SqlCommandUpdat eHospital.Param eters.Add(New
SqlClient.SqlPa rameter("@Hospi talName", txtHospitalName .Text))
SqlCommandUpdat eHospital.Comma ndText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProvid erNumber = @ProviderID)"

myConnection.Op en()
SqlCommandUpdat eHospital.Execu teNonQuery()
myConnection.Cl ose()

End sub

Roxie Aho
roxiea at usinternet.com
Dec 9 '05 #1
4 1399
Roxie,

I have not tried updating my DB the way you are mentioning above BUT
if i were to guess by looking at your code I would enclose your
@HospitalName with '@HospitalName' ...Let me know if it works, as I
have not tried it myself yet.

--Miguel

Dec 9 '05 #2

"Roxie Aho" <Ro******@discu ssions.microsof t.com> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
I'm trying to update a SQL2000 database through a web form. Visual
Basic.Net
2003,This is an abbreviated chunk of code.

The primary key field in the table is HospitalProvide rNumber. It is an
NVarChar (10). Some of the Hospital Provider Numbers begin with zero
(020026).

The table won't update with the WHERE clause. In my attempts to find
what's
working and not, I've easily filled the Hospital Name column with the name
of
one hospital by removing the WHERE so I know the update works.

I have a similar web form in which the HospitalSystemI D is a long integer
(autonumber) and similar code to update that table works as expected.

I'm guessing the difference is a long integer in the one that works, an
NVarChar in the one that doesn't

Any suggestions?

Private Sub btnSaveHospital _Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnSaveHospital .Click
Dim strConn As String
strConn = "integrated security=SSPI;d ata source=Aho1;per sist security
info=False;init ial catalog=HRRC"
Dim myConnection As New SqlClient.SqlCo nnection(strCon n)
Dim SqlCommandUpdat eHospital As New SqlClient.SqlCo mmand
SqlCommandUpdat eHospital.Conne ction = myConnection

SqlCommandUpdat eHospital.Param eters.Add(New
SqlClient.SqlPa rameter("@Provi derID", txtProviderNumb er.Text))
SqlCommandUpdat eHospital.Param eters.Add(New
SqlClient.SqlPa rameter("@Hospi talName", txtHospitalName .Text))
SqlCommandUpdat eHospital.Comma ndText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProvid erNumber = @ProviderID)"

myConnection.Op en()
SqlCommandUpdat eHospital.Execu teNonQuery()
myConnection.Cl ose()

End sub

Roxie Aho
roxiea at usinternet.com


I believe you need to enclose the ProviderID parameter in single quotes,
something roughly like this:

SqlCommandUpdat eHospital.Comma ndText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProvid erNumber = " & "'" &
@ProviderID &
"')"

Dec 9 '05 #3
When you use the particualr constructor for a SQLParameter object that you
are using, the SqlDBType for the SQLParameter object is inferred from the
..NET Framework type of the object that you are passing as a value.

The .NET Framework type String (type of TextBox.Text) infers to an NVarChar
however I would expect the inferred length to be an issue.

If I were writing you program then I would code the SQLParameters as
follows:
(For the purpose of the exercise I am assuming that roviderID is also
NvarChar(10).)

<object>.Parame ters.Add(New SqlParameter("@ ProviderID",
SqlDbType.NVarC har, 10)).Value = txtProviderNumb er.Text

<object>.Parame ters.Add(New SqlParameter("@ HospitalName",
SqlDbType.NVarC har, 10)).Value =txtHospitalNam e.Text

"Roxie Aho" <Ro******@discu ssions.microsof t.com> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
I'm trying to update a SQL2000 database through a web form. Visual
Basic.Net
2003,This is an abbreviated chunk of code.

The primary key field in the table is HospitalProvide rNumber. It is an
NVarChar (10). Some of the Hospital Provider Numbers begin with zero
(020026).

The table won't update with the WHERE clause. In my attempts to find
what's
working and not, I've easily filled the Hospital Name column with the name
of
one hospital by removing the WHERE so I know the update works.

I have a similar web form in which the HospitalSystemI D is a long integer
(autonumber) and similar code to update that table works as expected.

I'm guessing the difference is a long integer in the one that works, an
NVarChar in the one that doesn't

Any suggestions?

Private Sub btnSaveHospital _Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnSaveHospital .Click
Dim strConn As String
strConn = "integrated security=SSPI;d ata source=Aho1;per sist security
info=False;init ial catalog=HRRC"
Dim myConnection As New SqlClient.SqlCo nnection(strCon n)
Dim SqlCommandUpdat eHospital As New SqlClient.SqlCo mmand
SqlCommandUpdat eHospital.Conne ction = myConnection

SqlCommandUpdat eHospital.Param eters.Add(New
SqlClient.SqlPa rameter("@Provi derID", txtProviderNumb er.Text))
SqlCommandUpdat eHospital.Param eters.Add(New
SqlClient.SqlPa rameter("@Hospi talName", txtHospitalName .Text))
SqlCommandUpdat eHospital.Comma ndText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProvid erNumber = @ProviderID)"

myConnection.Op en()
SqlCommandUpdat eHospital.Execu teNonQuery()
myConnection.Cl ose()

End sub

Roxie Aho
roxiea at usinternet.com

Dec 10 '05 #4
Roxie,

Have a look at this simple sample how to use on the most simple way
parameters.

This is good suitable for a webapplication, for a windows application I
would take another style.

http://www.vb-tips.com/default.aspx?...6-7139b8970071

That extended sample is as well on our website.

I hope this helps,

Cor
"Roxie Aho" <Ro******@discu ssions.microsof t.com>
I'm trying to update a SQL2000 database through a web form. Visual
Basic.Net
2003,This is an abbreviated chunk of code.

The primary key field in the table is HospitalProvide rNumber. It is an
NVarChar (10). Some of the Hospital Provider Numbers begin with zero
(020026).

The table won't update with the WHERE clause. In my attempts to find
what's
working and not, I've easily filled the Hospital Name column with the name
of
one hospital by removing the WHERE so I know the update works.

I have a similar web form in which the HospitalSystemI D is a long integer
(autonumber) and similar code to update that table works as expected.

I'm guessing the difference is a long integer in the one that works, an
NVarChar in the one that doesn't

Any suggestions?

Private Sub btnSaveHospital _Click(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnSaveHospital .Click
Dim strConn As String
strConn = "integrated security=SSPI;d ata source=Aho1;per sist security
info=False;init ial catalog=HRRC"
Dim myConnection As New SqlClient.SqlCo nnection(strCon n)
Dim SqlCommandUpdat eHospital As New SqlClient.SqlCo mmand
SqlCommandUpdat eHospital.Conne ction = myConnection

SqlCommandUpdat eHospital.Param eters.Add(New
SqlClient.SqlPa rameter("@Provi derID", txtProviderNumb er.Text))
SqlCommandUpdat eHospital.Param eters.Add(New
SqlClient.SqlPa rameter("@Hospi talName", txtHospitalName .Text))
SqlCommandUpdat eHospital.Comma ndText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProvid erNumber = @ProviderID)"

myConnection.Op en()
SqlCommandUpdat eHospital.Execu teNonQuery()
myConnection.Cl ose()

End sub

Roxie Aho
roxiea at usinternet.com

Dec 10 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10554
by: Mark | last post by:
A beginner in this area, I have been able to read a record from a MySQL database and populate an HTML form (wow!). Now, my goal is to allow the user to edit the contents of the form and then update the record in MySQL. The problem is, as soon as the "Update" button (type="submit") is pressed, all of the data disappear from the form. How can that be prevented? Here is my code:
2
5266
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the user have to open a form and entera date so we know in report that the desiered check has been cleared. It takes me while to wrtie. But when I try to update the datagrid changes via dataset to MS Access 2003 I get an error that simply says...
5
3343
by: Klemens | last post by:
I get SQL30090 reason 18 by trying to do an insert in a federated table and an update in a local table in one transaction Do I have to change some settings to get done or ist this not possible by definition? Thanks Klemens
7
2429
by: PC Datasheet | last post by:
Looking for suggestions ---- A database was designed for a national automobile inspection program. In it's simplest form, the database has two tables: TblOwner OwnerID <Year/Make/Model owned by owner, Owner name/address, etc) TblInspection InspectionID
3
3451
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
0
4919
by: Vijay Balki | last post by:
I am fetching data in DataSet - myDataSet, from a remote database using a Web Service in my VB.NET client..Once I fetch it I store the data in XML file (myXMLFile) using the WriteXML method of the myDataSet. The connection to the Web Service is closed at this point. I update this XML file in my application, and when I am ready to send the data back, I load the XML file back to a DataSet - mySendDataSet, using ReadXML method. Now I...
8
2696
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
2
4173
by: TJ | last post by:
Hi All, I am having some trouble. I have created a database via the new database option inside VWD2005. Then and table or two. I have been able to perform INSERT and SELECT operations on the table, BUT cannot do an UPDATE. After the update command it says 1 row updated, but the data does not change. At one point I receieved a message stating something like (heavily paraphrased...):
2
3110
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i havnt tested the index yet ) so you can use an .UPDATE( dataTable ) on the data adapter. Otherwise you will get an exception error. Is this statement true? ---- Now me fumbling thru
3
3967
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID = ?
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.