如何自动将每个键入空字符串文本框的单个转换为整数 [英] how to automatically convert every single keyed in empty string textbox to integer

查看:48
本文介绍了如何自动将每个键入空字符串文本框的单个转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我很抱歉,如果这个问题之前已经发布过。我不知道如何检查用户输入的每个文本框..它是空字符串然后转换为0自动..



我的代码是:



Dim con As新的SqlConnection(connectionString)

Dim cmd4作为新的SqlCommand

cmd4.Connection = con

尝试

con。打开()

cmd4.CommandText =插入dailyloco_status([KTMB],[IRCON],[SMH],[total],[required],[short],[type],[datetime ])_

&值(@KTMB,@ IRCON,@ SMH,@ total,@ requirement,@ short,@ type,@ datetime)

Dim p1 As New SqlParameter(@ KTMB,SqlDbType.Int)

Dim p2 As New SqlParameter(@ IRCON,SqlDbType.Int)

Dim p3 As New SqlParameter (@SMH,SqlDbType.Int)

Dim p4 As New SqlParame ter(@ total,SqlDbType.Int)

Dim p5 As New SqlParameter(@ requirement,SqlDbType.Int)

Dim p6 As New SqlParameter(@ short,SqlDbType.Int)

Dim p7 As New SqlParameter(@ type,SqlDbType.SmallInt)

Dim p8 As New SqlParameter(@ datetime,SqlDbType .VarChar)





我的整数= 0到7步骤1



如果i = 0那么



p1.Value = Integer.Parse(TextBox12.Text)

p2.Value =整数。解析(TextBox13.Text)

p3.Value = Integer.Parse(TextBox14.Text)

p4.Value = Integer.Parse(TextBox15.Text)

p5.Value = 0

p6.Value = 0

p7.Value = 1



ElseIf i = 1然后



p1.Value = Int64.Parse(TextBox20.Text)

p2.Value = Int64.Parse(TextBox21.Text)

p3.Value = Int64.Parse(TextBox22.Text)

p4.Value = Int64.Parse(TextBox23.Text)

p5.Value = Int64.Parse(TextBox41.Text)

p6.Value = Int64.Parse(TextBox42.Text)

p7.Value = 2

totdaily_loco()

ElseIf i = 2然后

p1.Value = Int64.Parse(TextBox24.Text)

p2.Value = Int64.Parse(TextBox25.Text)

p3.Value = Int64.Parse(TextBox26.Text)

p4.Value = Int64.Parse(TextBox27.Text)

p5.Value = Int64。解析(TextBox43.Text)

p6.Value = Int64.Parse(TextBox76.Text)

p7.Value = 3

ElseIf i = 3然后

p1.Value = Integer.Parse(TextBox28.Text)

p2.Value = Integer.Parse(TextBox29.Text)

p3.Value = Integer.Parse(TextBox30.Text)

p4.Value = Integer.Parse(TextBox31.Text)

p5.Value = Integer.Parse(TextBox77.Text)

p6.Value = Integer.Parse(TextBox78.Text)

p7.Value = 4

ElseIf i = 4然后

p1.Value = Integer.Parse(TextBox32.Text)

p2.Value = Integer.Parse( TextBox33.Text)

p3.Value = Integer.Parse(TextBox34.Text)

p4.Value = Integer.Parse(TextBox35.Text)

p5.Value = Integer.Parse(TextBox79.Text)

p6.Value = Integer.Pars e(TextBox80.Text)

p7.Value = 5

ElseIf i = 5然后'总计

p1.Value = Integer.Parse( TextBox36.Text)

p2.Value = Integer.Parse(TextBox37.Text)

p3.Value = Integer.Parse(TextBox38.Text)

p4.Value = Integer.Parse(TextBox39.Text)

p5.Value = Integer.Parse(TextBox81.Text)

p6.Value = Integer.Parse( TextBox82.Text)

p7.Value = 6

ElseIf i = 6然后

p1.Value = Integer.Parse(TextBox44.Text)

p2.Value = Integer.Parse(TextBox45.Text)

p3.Value = Integer.Parse(TextBox46.Text)

p4。 Value = Integer.Parse(TextBox47.Text)

p5.Value = 0

p6.Value = 0

p7.Value = 6

结束如果

p8.Value = DateTime.Now

cmd4.Parameters.Add(p1)

cmd4.Parameters.Add(p2)

cmd4.Parameters.Add(p3)

cmd4 .Parameters.Add(p4)

cmd4.Parameters.Add(p5)

cmd4.Parameters.Add(p6)

cmd4.Parameters .Add(p7)

cmd4.Parameters.Add(p8)

cmd4.ExecuteNonQuery()

cmd4.Parameters.Clear()

下一页





Catch ex As Exception

MesgBox(ex.Message。 ToString())



最后

con.Close()



结束尝试

解决方案

请参阅我的评论问题。



以下是解决问题的方法:不要使用设计师;在代码中创建所有类似的控件(文本框),它将允许您使用数组或一些控件集合(如列表)。



-SA

hi all,

im sorry if this question is already been posted before.im not sure how to check every single textboxes that key in by user..if it is empty string then convert to 0 auto..

my code is:

Dim con As New SqlConnection(connectionString)
Dim cmd4 As New SqlCommand
cmd4.Connection = con
Try
con.Open()
cmd4.CommandText = "insert into dailyloco_status ([KTMB],[IRCON],[SMH],[total],[requirement],[short],[type],[datetime]) " _
& " values (@KTMB, @IRCON,@SMH,@total,@requirement,@short,@type,@datetime)"
Dim p1 As New SqlParameter("@KTMB", SqlDbType.Int)
Dim p2 As New SqlParameter("@IRCON", SqlDbType.Int)
Dim p3 As New SqlParameter("@SMH", SqlDbType.Int)
Dim p4 As New SqlParameter("@total", SqlDbType.Int)
Dim p5 As New SqlParameter("@requirement", SqlDbType.Int)
Dim p6 As New SqlParameter("@short", SqlDbType.Int)
Dim p7 As New SqlParameter("@type", SqlDbType.SmallInt)
Dim p8 As New SqlParameter("@datetime", SqlDbType.VarChar)


For i As Integer = 0 To 7 Step 1

If i = 0 Then

p1.Value = Integer.Parse(TextBox12.Text)
p2.Value = Integer.Parse(TextBox13.Text)
p3.Value = Integer.Parse(TextBox14.Text)
p4.Value = Integer.Parse(TextBox15.Text)
p5.Value = 0
p6.Value = 0
p7.Value = 1

ElseIf i = 1 Then

p1.Value = Int64.Parse(TextBox20.Text)
p2.Value = Int64.Parse(TextBox21.Text)
p3.Value = Int64.Parse(TextBox22.Text)
p4.Value = Int64.Parse(TextBox23.Text)
p5.Value = Int64.Parse(TextBox41.Text)
p6.Value = Int64.Parse(TextBox42.Text)
p7.Value = 2
totdaily_loco()
ElseIf i = 2 Then
p1.Value = Int64.Parse(TextBox24.Text)
p2.Value = Int64.Parse(TextBox25.Text)
p3.Value = Int64.Parse(TextBox26.Text)
p4.Value = Int64.Parse(TextBox27.Text)
p5.Value = Int64.Parse(TextBox43.Text)
p6.Value = Int64.Parse(TextBox76.Text)
p7.Value = 3
ElseIf i = 3 Then
p1.Value = Integer.Parse(TextBox28.Text)
p2.Value = Integer.Parse(TextBox29.Text)
p3.Value = Integer.Parse(TextBox30.Text)
p4.Value = Integer.Parse(TextBox31.Text)
p5.Value = Integer.Parse(TextBox77.Text)
p6.Value = Integer.Parse(TextBox78.Text)
p7.Value = 4
ElseIf i = 4 Then
p1.Value = Integer.Parse(TextBox32.Text)
p2.Value = Integer.Parse(TextBox33.Text)
p3.Value = Integer.Parse(TextBox34.Text)
p4.Value = Integer.Parse(TextBox35.Text)
p5.Value = Integer.Parse(TextBox79.Text)
p6.Value = Integer.Parse(TextBox80.Text)
p7.Value = 5
ElseIf i = 5 Then 'total
p1.Value = Integer.Parse(TextBox36.Text)
p2.Value = Integer.Parse(TextBox37.Text)
p3.Value = Integer.Parse(TextBox38.Text)
p4.Value = Integer.Parse(TextBox39.Text)
p5.Value = Integer.Parse(TextBox81.Text)
p6.Value = Integer.Parse(TextBox82.Text)
p7.Value = 6
ElseIf i = 6 Then
p1.Value = Integer.Parse(TextBox44.Text)
p2.Value = Integer.Parse(TextBox45.Text)
p3.Value = Integer.Parse(TextBox46.Text)
p4.Value = Integer.Parse(TextBox47.Text)
p5.Value = 0
p6.Value = 0
p7.Value = 6
End If
p8.Value = DateTime.Now
cmd4.Parameters.Add(p1)
cmd4.Parameters.Add(p2)
cmd4.Parameters.Add(p3)
cmd4.Parameters.Add(p4)
cmd4.Parameters.Add(p5)
cmd4.Parameters.Add(p6)
cmd4.Parameters.Add(p7)
cmd4.Parameters.Add(p8)
cmd4.ExecuteNonQuery()
cmd4.Parameters.Clear()
Next


Catch ex As Exception
MesgBox(ex.Message.ToString())

Finally
con.Close()

End Try

解决方案

Please see my comment to the question.

Here is how you can resolve the problem: don't use the designer; create all similar controls (text boxes) in code, it will allow you to use arrays or some collections of controls (such as lists).

—SA


这篇关于如何自动将每个键入空字符串文本框的单个转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆