请帮忙!!如何在vb.net中增加行的值 [英] Please help!! How to increment the value of rows in vb.net
本文介绍了请帮忙!!如何在vb.net中增加行的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果表为null,我希望row(0)的值从100000开始,这就是我想检查行(0)的原因,如果值为null,则textbox14应该由100000所以我可以将它保存到表中。以下是我迄今为止完成此任务所做的工作。
私有 Sub autoincrement()
getconnect()
如果 con.State = ConnectionState.Closed 然后
con.Open()
结束 如果
ds.Tables.Add(dt)
Dim reg_id As Double
reg_id = ds.Tables( 0 )。计算( Max(registrationID), Nothing )
如果 reg_id = vbNull 那么
TextBox14.Text = 100000
否则
TextBox14.Text = reg_id + 1
结束 如果
结束 Sub
当我开始调试时,我看到此消息屏幕 -
从类型''DBNull''转换为''Double''无效。
解决方案
请更改你的代码如下
私人 Sub autoincrement()
getconnect()
如果 con.State = ConnectionState.Closed 那么
con.Open()
结束 如果
ds。 Tables.Add(dt)
如果 ds.Tables.Rows.Count<> 0 然后
Dim reg_id As Double = 0
reg_id = ds.Tables( 0 )。计算( Max(registrationID), Nothing )
TextBox14.Text = reg_id + 1
其他
TextBox14.Text = 100000
结束 如果
结束 Sub
在为reg_id赋值之前,请检查表中的值是否为null。请注意,您需要检查DbNull.Value
而不是没有
。
< blockquote>
私有 Sub autoincrement()
getconnect()
如果 con.State = ConnectionState.Closed 那么
con.Open()
结束 如果
ds.Tables.Add(dt)
Dim reg_id 作为 Double
reg_id = ds.Tables( 0 )。计算( Max(registrationID), Nothing )
' -------------请注意这里----------------------------- -
' 获取最大行索引
Dim lastRowIndex 作为 整数 = ds.Tables( 0 )。Rows.Count - 1
如果 lastRowIndex< 0 然后
' < span class =code-comment>零行
TextBox14.Text = 100000
否则
Dim IsNum As BooleanIsNum = Double .TryParse(ds.Tables( 0 )。行(lastRowIndex)& _( registrationID)。ToString,regid)
TextBox14。 Text = reg_id + 1
结束 如果
' -------------- ---------------------------------------------
结束 Sub
I want the value of row(0) to be start from 100000 if the table is null, and that''s why I want to check the row(0) and if the value is null, textbox14 should be filled by 100000 so that I can save it to the table. Here''s what I''ve done so far for this task.
Private Sub autoincrement()
getconnect()
If con.State = ConnectionState.Closed Then
con.Open()
End If
ds.Tables.Add(dt)
Dim reg_id As Double
reg_id = ds.Tables(0).Compute("Max(registrationID)", Nothing)
If reg_id = vbNull Then
TextBox14.Text = "100000"
Else
TextBox14.Text = reg_id + 1
End If
End Sub
When I start debugging, I see this message on the screen--
Conversion from type ''DBNull'' to type ''Double'' is not valid.
解决方案
Please change your code like below
Private Sub autoincrement() getconnect() If con.State = ConnectionState.Closed Then con.Open() End If ds.Tables.Add(dt) If ds.Tables.Rows.Count <> 0 Then Dim reg_id As Double = 0 reg_id = ds.Tables(0).Compute("Max(registrationID)", Nothing) TextBox14.Text = reg_id + 1 Else TextBox14.Text = "100000" End If End Sub
Before assigning value to reg_id, check if the value in the table is null or not. Note that you need to check forDbNull.Value
and not fornothing
.
Private Sub autoincrement() getconnect() If con.State = ConnectionState.Closed Then con.Open() End If ds.Tables.Add(dt) Dim reg_id As Double reg_id = ds.Tables(0).Compute("Max(registrationID)", Nothing) '------------- Take note here------------------------------- 'Get the max row index Dim lastRowIndex As Integer = ds.Tables(0).Rows.Count - 1 If lastRowIndex < 0 Then ' zero rows TextBox14.Text = "100000" Else Dim IsNum As BooleanIsNum = Double.TryParse(ds.Tables(0).Row(lastRowIndex) & _("registrationID").ToString ,regid) TextBox14.Text = reg_id + 1 End If '----------------------------------------------------------- End Sub
这篇关于请帮忙!!如何在vb.net中增加行的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文