473,395 Members | 1,527 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,395 software developers and data experts.

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 HospitalProviderNumber. 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 HospitalSystemID 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.EventArgs) Handles btnSaveHospital.Click
Dim strConn As String
strConn = "integrated security=SSPI;data source=Aho1;persist security
info=False;initial catalog=HRRC"
Dim myConnection As New SqlClient.SqlConnection(strConn)
Dim SqlCommandUpdateHospital As New SqlClient.SqlCommand
SqlCommandUpdateHospital.Connection = myConnection

SqlCommandUpdateHospital.Parameters.Add(New
SqlClient.SqlParameter("@ProviderID", txtProviderNumber.Text))
SqlCommandUpdateHospital.Parameters.Add(New
SqlClient.SqlParameter("@HospitalName", txtHospitalName.Text))
SqlCommandUpdateHospital.CommandText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProviderNumber = @ProviderID)"

myConnection.Open()
SqlCommandUpdateHospital.ExecuteNonQuery()
myConnection.Close()

End sub

Roxie Aho
roxiea at usinternet.com
Dec 9 '05 #1
4 1376
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******@discussions.microsoft.com> wrote in message
news:F2**********************************@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 HospitalProviderNumber. 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 HospitalSystemID 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.EventArgs) Handles btnSaveHospital.Click
Dim strConn As String
strConn = "integrated security=SSPI;data source=Aho1;persist security
info=False;initial catalog=HRRC"
Dim myConnection As New SqlClient.SqlConnection(strConn)
Dim SqlCommandUpdateHospital As New SqlClient.SqlCommand
SqlCommandUpdateHospital.Connection = myConnection

SqlCommandUpdateHospital.Parameters.Add(New
SqlClient.SqlParameter("@ProviderID", txtProviderNumber.Text))
SqlCommandUpdateHospital.Parameters.Add(New
SqlClient.SqlParameter("@HospitalName", txtHospitalName.Text))
SqlCommandUpdateHospital.CommandText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProviderNumber = @ProviderID)"

myConnection.Open()
SqlCommandUpdateHospital.ExecuteNonQuery()
myConnection.Close()

End sub

Roxie Aho
roxiea at usinternet.com


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

SqlCommandUpdateHospital.CommandText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProviderNumber = " & "'" &
@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>.Parameters.Add(New SqlParameter("@ProviderID",
SqlDbType.NVarChar, 10)).Value = txtProviderNumber.Text

<object>.Parameters.Add(New SqlParameter("@HospitalName",
SqlDbType.NVarChar, 10)).Value =txtHospitalName.Text

"Roxie Aho" <Ro******@discussions.microsoft.com> wrote in message
news:F2**********************************@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 HospitalProviderNumber. 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 HospitalSystemID 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.EventArgs) Handles btnSaveHospital.Click
Dim strConn As String
strConn = "integrated security=SSPI;data source=Aho1;persist security
info=False;initial catalog=HRRC"
Dim myConnection As New SqlClient.SqlConnection(strConn)
Dim SqlCommandUpdateHospital As New SqlClient.SqlCommand
SqlCommandUpdateHospital.Connection = myConnection

SqlCommandUpdateHospital.Parameters.Add(New
SqlClient.SqlParameter("@ProviderID", txtProviderNumber.Text))
SqlCommandUpdateHospital.Parameters.Add(New
SqlClient.SqlParameter("@HospitalName", txtHospitalName.Text))
SqlCommandUpdateHospital.CommandText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProviderNumber = @ProviderID)"

myConnection.Open()
SqlCommandUpdateHospital.ExecuteNonQuery()
myConnection.Close()

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******@discussions.microsoft.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 HospitalProviderNumber. 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 HospitalSystemID 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.EventArgs) Handles btnSaveHospital.Click
Dim strConn As String
strConn = "integrated security=SSPI;data source=Aho1;persist security
info=False;initial catalog=HRRC"
Dim myConnection As New SqlClient.SqlConnection(strConn)
Dim SqlCommandUpdateHospital As New SqlClient.SqlCommand
SqlCommandUpdateHospital.Connection = myConnection

SqlCommandUpdateHospital.Parameters.Add(New
SqlClient.SqlParameter("@ProviderID", txtProviderNumber.Text))
SqlCommandUpdateHospital.Parameters.Add(New
SqlClient.SqlParameter("@HospitalName", txtHospitalName.Text))
SqlCommandUpdateHospital.CommandText = "UPDATE tblHospitals SET
HospitalName = @HospitalName WHERE (HospitalProviderNumber = @ProviderID)"

myConnection.Open()
SqlCommandUpdateHospital.ExecuteNonQuery()
myConnection.Close()

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
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...
2
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...
5
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...
7
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...
3
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...
0
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...
8
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. ...
2
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...
2
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...
3
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.