str1 = "insert into 领料单 values ('" & TextBox1.Text & "','" & TextBox2.Text & "'," _
+ "'" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "'," _
+ "'" & cb1 & "','" & TextBox7.Text & "','" & DataGridView2.CurrentRow.Cells(0).Value & "'," _
+ "'" & DataGridView2.CurrentRow.Cells(1).Value & "','" & DataGridView2.CurrentRow.Cells(2).Value & "'," _
+ "'" & DataGridView2.CurrentRow.Cells(3).Value & "','" & DataGridView2.CurrentRow.Cells(4).Value & "'," _
+ "'" & DataGridView2.CurrentRow.Cells(5).Value & "','" & DataGridView2.CurrentRow.Cells(6).Value & "'," _
+ "'" & DataGridView2.CurrentRow.Cells(7).Value & "','" & DataGridView2.CurrentRow.Cells(8).Value & "')"
Dim con As New SqlCommand(str1, tt)
con.ExecuteNonQuery()刚才本来想把界面也发上来的,但是发了好几次都失败就不发了,说一下
界面就是form 里面上面有几个textbox 然后下面是一个datagridview(多行数据)
textbox datagridview
1 1
2
3
我就是想要向数据库中插入三行数据
textbox datagridview
1 1
1 2
1 3
写了上面的代码,但是只能插入一行,请高人指点,怎样才能同时插入三行,先谢谢了。
+ "'" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "'," _
+ "'" & cb1 & "','" & TextBox7.Text & "','" & DataGridView2.CurrentRow.Cells(0).Value & "'," _
+ "'" & DataGridView2.CurrentRow.Cells(1).Value & "','" & DataGridView2.CurrentRow.Cells(2).Value & "'," _
+ "'" & DataGridView2.CurrentRow.Cells(3).Value & "','" & DataGridView2.CurrentRow.Cells(4).Value & "'," _
+ "'" & DataGridView2.CurrentRow.Cells(5).Value & "','" & DataGridView2.CurrentRow.Cells(6).Value & "'," _
+ "'" & DataGridView2.CurrentRow.Cells(7).Value & "','" & DataGridView2.CurrentRow.Cells(8).Value & "')"
Dim con As New SqlCommand(str1, tt)
con.ExecuteNonQuery()刚才本来想把界面也发上来的,但是发了好几次都失败就不发了,说一下
界面就是form 里面上面有几个textbox 然后下面是一个datagridview(多行数据)
textbox datagridview
1 1
2
3
我就是想要向数据库中插入三行数据
textbox datagridview
1 1
1 2
1 3
写了上面的代码,但是只能插入一行,请高人指点,怎样才能同时插入三行,先谢谢了。
解决方案 »
- 如何把数据用“图”的形式表现出来?有什么控件?(今天没分可给了,求各位好心大虾帮忙)
- sendmessage使用问题
- 如何获取文件的状态
- 请教一个入门问题……关于工程保存方面的问题。
- API函数 FindNextFile ?
- 请问能用VB实现将EXCEL转换成相应的ACCESS吗?提供相关资料也可以!高分求助!
- 关于发票打印,用printer可行吗?
- To 斑竹playyuer:你用什么魔法成为本月第一的?昨天上午你的分数才600,下午就成1902了.
- uguess!!!uguess!!!!!!!!!!!uguess!!!!!!!!!!!!!!!!!!!!!!!!!!有个问题阿.............快来....
- 歪批程序语言
- 请帮帮我
- excel vba编程
str1 = "select * from 领料单"
Dim con As New SqlCommand(str1, tt)
con.ExecuteNonQuery()
For i = 1 To 3
With con
.AddNew
.Fields(0) = trim(text1.text)
.Fields(1) = datagridview2.rows(i).cells(1).value
End With
Next i
con.Update
con.Close
Set con = Nothing
select 出的数据放到了 datagrid 里面
产品品号 主件品号 零件编号
1000773100 1030554300 1654564567
1000773100 1030554300 4687645464
1000773100 1030554300 8745454456
然后我写了这样的程序
Dim i As Integer
For i = 0 To Me.DataGridView1.Rows.Count - 2
My.Forms.Form1.TextBox4.Text = Me.DataGridView1.CurrentRow.Cells(0).Value
My.Forms.Form1.TextBox5.Text = Me.DataGridView1.CurrentRow.Cells(1).Value
My.Forms.Form1.DataGridView2.Item(0, i).Value = DataGridView1.CurrentRow.Cells(2).Value
My.Forms.Form1.DataGridView2.Item(1, i).Value = DataGridView1.CurrentRow.Cells(3).Value
My.Forms.Form1.DataGridView2.Item(2, i).Value = DataGridView1.CurrentRow.Cells(4).Value
My.Forms.Form1.DataGridView2.Item(3, i).Value = DataGridView1.CurrentRow.Cells(5).Value
Next i
老是会出现一个超出索引的错误,请指点程序哪里有问题,非常的感激。
For i = 0 To Me.DataGridView1.Rows.Count - 2
-------------------------------------------------
当DataGrisview1的行数等于0或1时就会出错.
2、用Insert into tb select FieldName ... Union All select FieldName ...