我有一个datagridview1,它有5列,我从datagridview2中添加到该gridview项,这没什么错,现在当我尝试使用2面额for循环从Datagridview1中获取这些值时,将其插入到我的sql db中,则显示此错误。
索引超出范围。必须为非负数且小于集合的大小。参数名称索引。
我希望我解释得很好。
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
con.ConnectionString = "Data Source = OMAR\MSSQLSERVER01;Initial Catalog=AccountsC20;Persist Security Info=True;User ID=ofamo;"
con.Open()
cmd.Connection = con
Dim Selected = ListBox1.SelectedValue.ToString()
If Selected = "0" Then
MessageBox.Show("Make sure to select a valued product")
Else
MessageBox.Show((TextBox4.Text) + 1)
For i As Integer = 0 To DataGridView1.RowCount - 1
For j As Integer = 0 To DataGridView1.ColumnCount - 1
cmd.CommandText = "Insert into SInvoice Values('SIV-" & (TextBox4.Text) + 1 & "',0," & j + 1 & ",(select nodeno from productmast where arabic_name= '" & Selected & "')," & DataGridView1.Item(i, 2).Value & ",0.000000,'2019-04-04 13:40:00'," & DataGridView1.Item(i, 4).Value & "," & DataGridView1.Item(i, 3).Value & ",'',0,1,1,1,1,'04/04/2019 13:39:44','',1.000000,1,0,'','b',0.000000,5,0.000000," & DataGridView1.Item(i, 3).Value & ",'Nos',1.000000,'','','','','','','','','','','','','','','','','','','','','',0,3,'" & Label4.Text & "',1,1,1,1,1,1,0.000000)"
cmd.ExecuteNonQuery()
Next
Next
答案 0 :(得分:0)
您将以哪种方式填充datagridview 1或2?如果您使用的是喜欢数据表的数据,或者可以使用require_once("../../../../wp-load.php");
$buildName = $_POST['buildName'];
$myBuild = $_POST['array'];
$myBuild2 = json_decode('array');
echo $myBuild2;
print_r($myBuild);
$wpdb->insert('wp_usermeta', array(
'meta_key' => $buildName,
'meta_value' => $myBuild2
),
array(
)
);
非常轻松,快速地将数据传输到sql数据库,但是我不知道您是否希望这样做或是否使用数据表等。
sqlbulkcopy
尝试在每个循环中使用,看看是否有所不同