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

Error while updating db

im using asp and vs03 vb but i understand some c#

im trying to make a checkbox's checked (true|false) value update a sqlserver
2000 table.

the db type for that field is bit. and i would like to keep it that way so
the datagrid shows the check box instead of a text value

im getting this error

Error is ->Syntax error converting the varchar value 'F' to a column of data
type bit.

code ****************
Dim one As Integer ' this is only trying to pass an int wiould have
worked
' i also tried to pass a boolean
string and chars didnt work
' i tried casting the update
querystring fields but i dont know weather i did that right please review it
below
one = 0
Dim dt As DataTable

dt = Me.DsUsers2.Tables("usertable")

Dim dr1 As DataRow()

dr1 = dt.Select("UserId = '" & Me.lblUserId.Text & "'")

dr1(0)("UserId") = dr1(0)("UserId") ' only reason im setting them
to themselves is because when i dont set them it gives the same error and
just to show the complete table

dr1(0)("fname") = dr1(0)("fname")

dr1(0)("lname") = dr1(0)("lname")

dr1(0)("departament") = Int32.Parse(ddlDepts.SelectedItem.Value)

dr1(0)("isdepartamenthead") = chbDepartamenthead.checked

dr1(0)("iscoordinator") = one

dr1(0)("extension") = dr1(0)("extension")

dr1(0)("email") = dr1(0)("email")

Me.SqlDataAdapter1.Update(dr1)

/code **********************

update query string generated by vs -UPDATE usertable SET UserId =
@UserId, Fname = @Fname, Lname = @Lname, Departament = @Departament,
isdepartamenthead = @isdepartamenthead, iscoordinator = @iscoordinator,
extension = @extension, email = @email WHERE (UserId = @Original_UserId);
SELECT UserId, Fname, Lname, Departament, isdepartamenthead, iscoordinator,
extension, email FROM usertable WHERE (UserId = @UserId)
with my cast -UPDATE usertable SET UserId = @UserId, Fname = @Fname, Lname
= @Lname, Departament = @Departament, isdepartamenthead = cast(
@isdepartamenthead as bit) , iscoordinator = cast( @iscoordinator as bit),
extension = @extension, email = @email WHERE (UserId = @Original_UserId);
SELECT UserId, Fname, Lname, Departament, isdepartamenthead, iscoordinator,
extension, email FROM usertable WHERE (UserId = @UserId)

this cast doesnt work when tried the gives same error

Thank you for your help.


Oct 23 '07 #1
2 1943
Hi,
The error message is detailed enough to realize that you are passing a F
instead of a 0 or 1 to a bit field.

Just use 0 for false and 1 for true.

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Marcin Wiszowaty" <mw********@finmedsys.comwrote in message
news:ed**************@TK2MSFTNGP06.phx.gbl...
im using asp and vs03 vb but i understand some c#

im trying to make a checkbox's checked (true|false) value update a
sqlserver 2000 table.

the db type for that field is bit. and i would like to keep it that way so
the datagrid shows the check box instead of a text value

im getting this error

Error is ->Syntax error converting the varchar value 'F' to a column of
data type bit.

code ****************
Dim one As Integer ' this is only trying to pass an int wiould have
worked
' i also tried to pass a boolean
string and chars didnt work
' i tried casting the update
querystring fields but i dont know weather i did that right please review
it below
one = 0
Dim dt As DataTable

dt = Me.DsUsers2.Tables("usertable")

Dim dr1 As DataRow()

dr1 = dt.Select("UserId = '" & Me.lblUserId.Text & "'")

dr1(0)("UserId") = dr1(0)("UserId") ' only reason im setting them
to themselves is because when i dont set them it gives the same error and
just to show the complete table

dr1(0)("fname") = dr1(0)("fname")

dr1(0)("lname") = dr1(0)("lname")

dr1(0)("departament") = Int32.Parse(ddlDepts.SelectedItem.Value)

dr1(0)("isdepartamenthead") = chbDepartamenthead.checked

dr1(0)("iscoordinator") = one

dr1(0)("extension") = dr1(0)("extension")

dr1(0)("email") = dr1(0)("email")

Me.SqlDataAdapter1.Update(dr1)

/code **********************

update query string generated by vs -UPDATE usertable SET UserId =
@UserId, Fname = @Fname, Lname = @Lname, Departament = @Departament,
isdepartamenthead = @isdepartamenthead, iscoordinator = @iscoordinator,
extension = @extension, email = @email WHERE (UserId = @Original_UserId);
SELECT UserId, Fname, Lname, Departament, isdepartamenthead,
iscoordinator, extension, email FROM usertable WHERE (UserId = @UserId)
with my cast -UPDATE usertable SET UserId = @UserId, Fname = @Fname,
Lname = @Lname, Departament = @Departament, isdepartamenthead = cast(
@isdepartamenthead as bit) , iscoordinator = cast( @iscoordinator as
bit), extension = @extension, email = @email WHERE (UserId =
@Original_UserId); SELECT UserId, Fname, Lname, Departament,
isdepartamenthead, iscoordinator, extension, email FROM usertable WHERE
(UserId = @UserId)

this cast doesnt work when tried the gives same error

Thank you for your help.


Oct 23 '07 #2
First of all thank you for the effort
secon as i said
when i used the
dr1(0)("isdepartamenthead") = 1 or char variable or anything else

vs was casting the asignment to true or false as varchar anyway

i had to change the .xsd file for the dataset for the 2 fields from bools to
unsignedbyte

now i get either a 0 for false or 1 for true in my datagrid but the update
works



"Marcin Wiszowaty" <mw********@finmedsys.comwrote in message
news:ed**************@TK2MSFTNGP06.phx.gbl...
im using asp and vs03 vb but i understand some c#

im trying to make a checkbox's checked (true|false) value update a
sqlserver 2000 table.

the db type for that field is bit. and i would like to keep it that way so
the datagrid shows the check box instead of a text value

im getting this error

Error is ->Syntax error converting the varchar value 'F' to a column of
data type bit.

code ****************
Dim one As Integer ' this is only trying to pass an int wiould have
worked
' i also tried to pass a boolean
string and chars didnt work
' i tried casting the update
querystring fields but i dont know weather i did that right please review
it below
one = 0
Dim dt As DataTable

dt = Me.DsUsers2.Tables("usertable")

Dim dr1 As DataRow()

dr1 = dt.Select("UserId = '" & Me.lblUserId.Text & "'")

dr1(0)("UserId") = dr1(0)("UserId") ' only reason im setting them
to themselves is because when i dont set them it gives the same error and
just to show the complete table

dr1(0)("fname") = dr1(0)("fname")

dr1(0)("lname") = dr1(0)("lname")

dr1(0)("departament") = Int32.Parse(ddlDepts.SelectedItem.Value)

dr1(0)("isdepartamenthead") = chbDepartamenthead.checked

dr1(0)("iscoordinator") = one

dr1(0)("extension") = dr1(0)("extension")

dr1(0)("email") = dr1(0)("email")

Me.SqlDataAdapter1.Update(dr1)

/code **********************

update query string generated by vs -UPDATE usertable SET UserId =
@UserId, Fname = @Fname, Lname = @Lname, Departament = @Departament,
isdepartamenthead = @isdepartamenthead, iscoordinator = @iscoordinator,
extension = @extension, email = @email WHERE (UserId = @Original_UserId);
SELECT UserId, Fname, Lname, Departament, isdepartamenthead,
iscoordinator, extension, email FROM usertable WHERE (UserId = @UserId)
with my cast -UPDATE usertable SET UserId = @UserId, Fname = @Fname,
Lname = @Lname, Departament = @Departament, isdepartamenthead = cast(
@isdepartamenthead as bit) , iscoordinator = cast( @iscoordinator as
bit), extension = @extension, email = @email WHERE (UserId =
@Original_UserId); SELECT UserId, Fname, Lname, Departament,
isdepartamenthead, iscoordinator, extension, email FROM usertable WHERE
(UserId = @UserId)

this cast doesnt work when tried the gives same error

Thank you for your help.


Oct 23 '07 #3

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

Similar topics

5
by: azgoddess1 | last post by:
During the installation I get these error messages: ***** SQL1390C The environment variable DB2Instance is not defined or is invalid An error ocured while loading the command "C:\Program...
18
by: Steve | last post by:
Hi I have a really weird problem and any assistance would be welcome. I have developed an app in Access 2002. The app runs perfectly on the development machine. I have packaged the app using...
0
by: mbenedict | last post by:
I am rather new at this code and am attempting to modify existing code to use clob datatypes, which I have never used before. The database tables have been set up for clob data. When trying to use...
0
by: Toralf Kirsten | last post by:
Hi all, we have installed DB2 V9.5 Trial on a Fedora 6 Linux box (32bit). Since the box is included in a NIS we have manually created db2 users db2inst, dasusr and db2fenc on this box (not in the...
2
by: Smurfas | last post by:
What's wrong? Compiletor don't show anything, but whet I start program show this error: "Error updating the employee details!" protected void Button1_Click(object sender, EventArgs e) ...
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: 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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.