VB.NET编程 ExecuteNonQuery: CommandText 属性尚未初始化 10
要实现将文本框和组合框中的数据更新到SQL数据库代码:DimconAsNewSqlClient.SqlConnectioncon=Helper.getSqlConnect...
要实现将文本框和组合框中的数据更新到SQL数据库
代码: Dim con As New SqlClient.SqlConnection
con = Helper.getSqlConnection()
con.Open()
Dim a(6, 3) As Integer
Dim i As Integer
For i = 1 To 6
a(i, 3) = ComboBox(i).selectvalue
Next i
a(1, 1) = Val(TextBox1.Text)
a(1, 2) = Val(TextBox2.Text)
a(2, 1) = Val(TextBox3.Text)
a(2, 2) = Val(TextBox4.Text)
a(3, 1) = Val(TextBox5.Text)
a(3, 2) = Val(TextBox6.Text)
a(4, 1) = Val(TextBox7.Text)
a(4, 2) = Val(TextBox8.Text)
a(5, 1) = Val(TextBox9.Text)
a(5, 2) = Val(TextBox10.Text)
a(6, 1) = Val(TextBox1.Text)
a(6, 2) = Val(TextBox1.Text)
For i = 1 To 6
Dim cmdtext As String = "insert into time(location,min,max,type) values (" + i.ToString + "," + a(i, 1).ToString + a(i, 2).ToString + "," + a(i, 3).ToString + ")"
Next i
cmd = New SqlClient.SqlCommand(cmdtext, con)
cmd.ExecuteNonQuery()
con.Close() 展开
代码: Dim con As New SqlClient.SqlConnection
con = Helper.getSqlConnection()
con.Open()
Dim a(6, 3) As Integer
Dim i As Integer
For i = 1 To 6
a(i, 3) = ComboBox(i).selectvalue
Next i
a(1, 1) = Val(TextBox1.Text)
a(1, 2) = Val(TextBox2.Text)
a(2, 1) = Val(TextBox3.Text)
a(2, 2) = Val(TextBox4.Text)
a(3, 1) = Val(TextBox5.Text)
a(3, 2) = Val(TextBox6.Text)
a(4, 1) = Val(TextBox7.Text)
a(4, 2) = Val(TextBox8.Text)
a(5, 1) = Val(TextBox9.Text)
a(5, 2) = Val(TextBox10.Text)
a(6, 1) = Val(TextBox1.Text)
a(6, 2) = Val(TextBox1.Text)
For i = 1 To 6
Dim cmdtext As String = "insert into time(location,min,max,type) values (" + i.ToString + "," + a(i, 1).ToString + a(i, 2).ToString + "," + a(i, 3).ToString + ")"
Next i
cmd = New SqlClient.SqlCommand(cmdtext, con)
cmd.ExecuteNonQuery()
con.Close() 展开
1个回答
展开全部
Helper是什么?
con需要连接字符串的,一般在构造函数中带连接字符串哦
比如Dim con As New SqlClient.SqlConnection("Data Source=192.168.0.210;Initial Catalog=TileDB;User ID=sa;Password=123456;connect timeout=30")
con需要连接字符串的,一般在构造函数中带连接字符串哦
比如Dim con As New SqlClient.SqlConnection("Data Source=192.168.0.210;Initial Catalog=TileDB;User ID=sa;Password=123456;connect timeout=30")
追问
helper就是全局的一个变量,实现的就是和数据库的连接
追答
helper定义时需要初始化,初始化方法同上面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询