Checkbox in a datagrid VB.net 2005 (1 Viewer)

dr223

Registered User.
Local time
Today, 15:09
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 AsInteger

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

EndTry
Next irow


Thanks for any help given
 

jal

Registered User.
Local time
Today, 15:09
Joined
Mar 30, 2007
Messages
1,709
Quoting Error encountered can't change varchar to numeric.
This error seems to indicate a dataype mismatch. Single quotes are needed only if your database column is type nvarchar. Otherwise not. What datatype is your database column?
 

dr223

Registered User.
Local time
Today, 15:09
Joined
Nov 15, 2007
Messages
219
My datatype in the database is varchar(50). I expect it to write either a Yes / No in the respective data field.

Thanks
 

jal

Registered User.
Local time
Today, 15:09
Joined
Mar 30, 2007
Messages
1,709
Well then you may have to manually convert the datagrid value to a "Yes" or a "No" string.

Dim str as string
if DgvToPay.Rows(irow).Cells(3).Value = True then str = "Yes" Else str = "No"

then build this value "str" into your SQL string.
 

Users who are viewing this thread

Top Bottom