is there anyone there can help how to insert a multiple data using dgv in my database...i can insert a data but the only it is only rather two i want?
here is my code any can help i do appreciate tnx in advance.....student :-)
Code:' Create INSERT statement with named parameters nonqueryCommand.CommandText = _ "INSERT INTO ordetail (Account_code,description) VALUES (@Account_code,@description)" ' Add Parameters to Command Parameters collection nonqueryCommand.Parameters.Add("@Account_code", MySqlDbType.String, 0) nonqueryCommand.Parameters.Add("@description", MySqlDbType.String, 0) ' nonqueryCommand.Parameters.Add("@Col2", SqlDbType.VarChar, 50) ' Prepare command for repeated execution nonqueryCommand.Prepare() ' Data to be inserted For Each row As DataGridViewRow In DataGridView1.Rows If Not IsNothing(row.Cells(0).Value) Then ' For i As Integer = 0 To DataGridView1.Rows.Count - 1 With nonqueryCommand ' .Parameters[0].Value = datagridview1.Rows[i].Cells[0].Value .Parameters("@Account_code").Value = row.Cells(0).Value.ToString .Parameters("@description").Value = row.Cells(1).Value.ToString End With ' Next 'nonqueryCommand.Parameters("@Col2").Value = row.Cells(1).Value.ToString End If Next row nonqueryCommand.ExecuteNonQuery() ' nonqueryCommand.Parameters.Clear() Catch ex As MySqlException ' Display error Console.WriteLine("Error: " & ex.ToString()) Finally ' Close Connection tryCon.Close() MsgBox("Details hav been successfully added", MsgBoxStyle.Information, "ORdetail information") End Try


Reply With Quote



