add a checkbox "Yes/No" to the SQl database (1 Viewer)

dr223

Registered User.
Local time
Today, 10:20
Joined
Nov 15, 2007
Messages
219
Hallo,

I am working with VB.net 2005, what am trying to do is insert fields into a table in Sql database.

The table name is TblQuarPay

The following code works perfectly well but it doesn't populate the field ToPay in the database. Quoting Error encountered can't change varchar to numeric.
ToPay is a checkbox in the datagrid and it's always set to true i.e., ThreeState = True.

I would like to load either Yes or No to the database on the field column ToPay.

The specific line of code for the checkbox is;

DgvToPay.Rows(irow).Cells(3).Value & "', '" & _

Please review the code and any assistance will be highly appreciated


Dim irow As Integer

For irow = 0 To DgvToPay.Rows.Count - 1
Try
query = "INSERT INTO gprdsql.TblQuarPay (prac_no, prac_eid, num_pats, ToPay, AmounttobePaid) VALUES ('" & _
DgvToPay.Rows(irow).Cells(0).Value &
"', '" & _
DgvToPay.Rows(irow).Cells(1).Value &
"', '" & _
DgvToPay.Rows(irow).Cells(2).Value &
"', '" & _
DgvToPay.Rows(irow).Cells(3).Value &
"', '" & _
DgvToPay.Rows(irow).Cells(4).Value &
"')"
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception

End Try
Next irow


Thanks for any help given
 

tehNellie

Registered User.
Local time
Today, 17:20
Joined
Apr 3, 2007
Messages
751
If the database you're sending the query to Accepts a Boolean(true/false) as values, then you need to remove the quotes around them in your SQL String as you're effectively passing them as text values rather than booleans.

ie Values ("blah","blah","True")
rather than
Values ("blah","blah",True)

If not then you need to convert TRUE/FALSE into the appropriate values, the error message suggests that it expects a numeric value (rather than a bit?) rather than a boolean.
 

Users who are viewing this thread

Top Bottom