大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Dim obj As Object, objName As String, i As Integer
创新互联专注于东兴网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供东兴营销型网站建设,东兴网站制作、东兴网页设计、东兴网站官网定制、小程序制作服务,打造东兴网络公司原创品牌,更为您提供东兴网站排名全网营销落地服务。
i = 0
For Each obj In Me.Controls '枚举窗体所有控件
Debug.Print TypeName(obj)
If TypeName(obj) = "TextBox" Then '判读是否为文本框
i = i + 1
objName = obj.Name '获取文本控件名称,这里可以根据名称来判读赋值,也可以根据其他属性复制
obj.Text = "文本" i '文本框赋值
End If
Next
SqlConnection myconn = new SqlConnection(server=(local),uid=sa,pwd=sa,database=db);//连接数据库语句自己修改
myconn.Open();
SqlCommand mycmd = new SqlCommand();
mycmd.CommandText = "insert into abd(d,e,f) values (@a,@b,@c)";
mycmd.Parameters.AddWithValue("@a", a.Text);
mycmd.Parameters.AddWithValue("@b", b.Text);
mycmd.Parameters.AddWithValue("@c", c.Text);
mycmd.Connection = myconn;
mycmd.ExecuteNonQuery();
myconn.Close();
是这个办法的,只是要加一句:
TextBox1.SelectionLength = 0
TextBox1.SelectionStart = TextBox1.Text.Length
TextBox1.ScrollToCaret()
另外,文本框的内容修改后要再次执行上面的三句代码
Dim mycon As New SqlConnection(connstrs)
Dim sqlStr As String = "SELECT * FROM [Column] FROM [Table]"
Dim cmd As New SqlCommand(sqlStr, mycon)
Dim reader = cmd.ExecuteReader()
Dim i As Integer = 1
While reader.Read()
Dim txt As New TextBox()
txt.Name = "txt" + i
txt.Size = New Size(100, 20) '文本框大小
txt.Location = New Point(50, i * 20 + 20)'left:50 top:随便写的,自己看着调
txt.Text = reader.GetValue(0).ToString()
Me.Controls.Add(txt) 'Me 可以改为你要添加上去的对象
End While
'未经过运行,自己调试看看能否OK
1、首先,点击保存按钮后应检查文本框内容。
2其次,如果在文本框4中输入的值以400开头则保存反之更改为400。
3、最后,再次检查文本框5如果文本框5中的值为29或31则保存反之则更改即可。
呵呵,就当练手了
Add_VB.aspx 代码
%@ Page Language="VB" AutoEventWireup="false" CodeFile="Add_VB.aspx.vb" Inherits="测试代码_Add_VB" %
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head runat="server"
title实现加运算/title
/head
body
form id="form1" runat="server"
div
asp:TextBox ID="TextBox1" runat="server" Width="66px"/asp:TextBox
asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="必须为数字" ValidationExpression="(\d+(\.\d)?){1,1}"/asp:RegularExpressionValidator
br /
asp:TextBox ID="TextBox2" runat="server" Width="66px"/asp:TextBox
asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="必须为数字" ValidationExpression="\d+(\.\d)?"/asp:RegularExpressionValidator
br /
asp:TextBox ID="TextBox3" runat="server" Width="66px"/asp:TextBox
asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="TextBox3" ErrorMessage="必须为数字" ValidationExpression="\d+(\.\d)?"/asp:RegularExpressionValidator
br /
asp:TextBox ID="TextBox4" runat="server" Width="66px"/asp:TextBox
asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="TextBox4" ErrorMessage="必须为数字" ValidationExpression="\d+(\.\d)?"/asp:RegularExpressionValidator
br /
asp:TextBox ID="TextBox5" runat="server" ReadOnly="True"/asp:TextBox
asp:Button ID="Button1" runat="server" Text="求和" Width="78px" /
/div
/form
/body
/html
Add_VB.aspx.vb 代码
Partial Class 测试代码_Add_VB
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Double = TextBox1.Text
Dim b As Double = TextBox2.Text
Dim c As Double = TextBox3.Text
Dim d As Double = TextBox4.Text
TextBox5.Text = a + b + c + d
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If TextBox1.Text = "" Then
TextBox1.Text = 0
End If
If TextBox2.Text = "" Then
TextBox2.Text = 0
End If
If TextBox3.Text = "" Then
TextBox3.Text = 0
End If
If TextBox4.Text = "" Then
TextBox4.Text = 0
End If
End Sub
End Class