循环批量添加数据问题,有人会吗??
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New
System.Data.SqlClient.SqlConnection( "server=;database=BGMS;uid=sa;pwd=jsj; ")
conn.Open()
Dim i As Integer
Dim str1, ttext1 As String
For i = 1 To 10
ttext1 = "TextBox " & i & ".text "
If Trim( "TextBox " & i & ".text ") <> " " Then
Dim cmds As New System.Data.SqlClient.SqlCommand( "insert into jishu(name,gongsi,dtime) values( ' " & Trim( "TextBox " & i & ".text ") & " ', ' " & DropDownList1.SelectedValue & " ', ' " & Now & " ') ", conn)
cmds.ExecuteNonQuery()
End If
Next
Response.Write( "添加成功! ")
conn.Close()
End Sub
问题出在了 "TextBox " & i & ".text "上
我想批量添加10条数据
textbox1
textbox2
textbox3
textbox4
textbox5
textbox6
textbox7
textbox8
textbox9
textbox10.text
我用循环批量链接字符串成10个控件
可是发现空间名字变成字符串后就不是变量了
就不能自动获取它本身的值了
请大家说说这个有什么好的解决方案吗???
------解决方案--------------------for(int i=1; i <=10; i++)
((TextBox)findcontrol[ "textbox1 "+i]).text
------解决方案--------------------可以用FindControl( "TextBox " + i)