将GridCellValue或NULL插入SQL Decimal列 [英] Insert GridCellValue or NULL into SQL Decimal column
问题描述
亲爱的专家,
我有一个数据类表格,其数据类型为十进制(5,2),并且来自vb.net应用程序使用devexpress gridview我正在将值更新到sql表中但如果网格单元格值为空,那么我需要插入NULL else gridrowcell值。有20个这样的列
,我需要检查NULL值,但是我从字符串"""获得转换。加倍是无效的。
$
if写条件的错误是什么?我也尝试过DBNULL.Value而不是dt,cdec(GridView1.GetRowCellValue(i,"col1"),cdbl(GridView1.GetRowCellValue(i,"col1")
I have a datbase table with datatype decimal(5,2) and from vb.net application using devexpress gridview I am updating values into the sql table but if the grid cell value is empty then I need to insert NULL else gridrowcell value. There are 20 such columns
where I need to check for NULL value but I get Conversion from string "" to double is not valid.
What is the mistake in the if condition am writing? I have also tried DBNULL.Value instead of dt, cdec( GridView1.GetRowCellValue(i,"col1"), cdbl(GridView1.GetRowCellValue(i,"col1")
GridView1.GetRowCellValue(i, "Col1")
dim dt as decimal =0.00
Dim v1 As Decimal = If(GridView1.GetRowCellValue(i, "col1") <> "", GridView1.GetRowCellValue(i, "Col1"), dt)
Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
dim dt as decimal = 0.00
For i As Integer = 0 To GridView1.DataRowCount
Dim v1 As Decimal = If(GridView1.GetRowCellValue(i, "col1") <> "", GridView1.GetRowCellValue(i, "Col1"), dt)
Dim v1 As Decimal= If(GridView1.GetRowCellValue(i, "col2") <> "", GridView1.GetRowCellValue(i, "Col2"), dt)
'
'
' similar code till 20 columns
Dim v20 As String = If(GridView1.GetRowCellValue(i, "col20") <> "", GridView1.GetRowCellValue(i, "Col20"), dt)
Dim r As String = "INSERT INTO [dbo].[MyTable] ([col1],[col2],[col3],[col4],[col5],.................,[col20])
values (v1,v2,v3,v4,v5 ...........,v20)
SQL.Execute(r)
If sql.HasException(True) Then Exit Sub
Next
End Sub
问候,
NewBInVB
NewBInVB
NewBInVB
推荐答案
首先,无论这是第三方网格还是Microsoft .NET网格,您都应该通过数据源访问数据,例如在DataGridView中它将是DataGridView.DataSource。假设它是DataGridView,DataSource设置为DataTable
(常用于处理后端数据),您将迭代行和字段以查看值是否为零并且相应地采取相应行动。
First off, no matter if this is a third party grid or a Microsoft .NET grid, you should be accessing data via the data source e.g. in a DataGridView it would be DataGridView.DataSource. Suppose it was a DataGridView with the DataSource set to a DataTable (common for working with backend data) you would iterate the rows and fields to see if a value was nothing and act accordingly.
无论如何,我建议在DevExpress的开发者论坛上提问。
Anyways I suggest asking your question in the developer's forum at DevExpress.
这篇关于将GridCellValue或NULL插入SQL Decimal列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!