Dear Experts,

From another sub routine am loading the datagrid from a sql datatable. Which is working fine. My code for inserting from datagrid to another sql table on a button click shows an error Conversion from string "" to double is not valid.

My datagridview looks like this after filling the datagridview from datasource (as you have mentioned).

Name:  MyData.png
Views: 1462
Size:  46.0 KB

From this I have to insert these values into MyTable on a click of a button,MySample SQL table has fields like this

Code:
Create Table MySample(
         SampleID uniqueidentified,
        [col1] [decimal](5, 2) NULL,
	[col2] [decimal](5, 2) NULL,
	[col3] [decimal](5, 2) NULL,
	[col4] [decimal](5, 2) NULL,
	[col5] [decimal](5, 2) NULL,  
        CONSTRAINT [PK_SampleID] PRIMARY KEY CLUSTERED )
So for each row of the datagridview above I have to insert it into MySample database table . For example row 1 (1636001) has no value in col 4, col5 so I have to insert NULL,

In SQL its very simple, I can type NULL if blank

Code:
INSERT INTO [dbo].[MySample] ([SampleID],[1],[2],[3],[4],[5]) VALUES ('1636001',3.40,4,2.30,NULL,NULL)
But in vb.net I'm not able to insert NULL value from the code so I'm passing each of the rowcell into a variable

Dim dt as String = "NULL"
Dim v1 As Decimal = If(GridView1.GetRowCellValue(i, "1") <> "", GridView1.GetRowCellValue(i, "1"), dt)
Dim v1 As Decimal= If(GridView1.GetRowCellValue(i, "2") <> "", GridView1.GetRowCellValue(i, "2"), dt)
'
'
' similar code till 5columns
Dim v5 As String = If(GridView1.GetRowCellValue(i, "5") <> "", GridView1.GetRowCellValue(i, "20"), dt


I need help in writing the IF condition for inserting the NULL if the gridrowcellvalue is blank. How to insert NULL for a decimal column from VB:NET?

Waiting for help.

Thanks
Arp