Error while updating db

M

Marcin Wiszowaty

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.
 
I

Ignacio Machin \( .NET/ C# MVP \)

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.
 
M

Marcin Wiszowaty

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top