This is a migrated thread and some comments may be shown as answers.

Using RadGridView to insert data in to MySql

2 Answers 148 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mahir
Top achievements
Rank 1
Mahir asked on 07 Mar 2017, 07:16 AM

Hello guys/girls, how are you?

I hope you can help me.

 

I need to use RadGridView to insert / update / delete data from MySql. VB.NET

I've used this code :

-------------------------------------------------------------------------------------------------

statustestera = Me.RadGridView1.SelectedRows.Item(0).ToString
            statuspantograf = Me.RadGridView1.SelectedRows.Item(1).ToString
            statusdispecer = Me.RadGridView1.SelectedRows.Item(2).ToString
            statusproizvodnja = Me.RadGridView1.SelectedRows.Item(3).ToString
            statusdokumentacija = Me.RadGridView1.SelectedRows.Item(4).ToString

            comm.Connection = cn
            comm.CommandText = "INSERT INTO TBL_Priprema_GROB(StatusTeseta, StatusPantograf, StatusDispecer, StatusProizvodnja, StatusDokumentacija) VALUES('" & statustestera & "','" & statuspantograf & "''" & statusdispecer & "','" & statusproizvodnja & "',' " & statusdokumentacija & "')"
            comm.ExecuteNonQuery()

 

------------------------------------------------

but it returns with the Index can not be negative or less..... error. 

 

Can you please help 

 

 

2 Answers, 1 is accepted

Sort by
0
Mahir
Top achievements
Rank 1
answered on 07 Mar 2017, 07:19 AM

UPDATE*

Here is the full code

 

  cn.Open()

        Dim statustestera, statuspantograf, statusdispecer, statusproizvodnja, statusdokumentacija
        Dim comm As New SqlCommand
        For i As Integer = 0 To Me.RadGridView1.Rows.Count + 1


            statustestera = Me.RadGridView1.SelectedRows.Item(6).ToString
            statuspantograf = Me.RadGridView1.SelectedRows.Item(5).ToString
            statusdispecer = Me.RadGridView1.SelectedRows.Item(7).ToString
            statusproizvodnja = Me.RadGridView1.SelectedRows.Item(9).ToString
            statusdokumentacija = Me.RadGridView1.SelectedRows.Item(8).ToString

            comm.Connection = cn
            comm.CommandText = "INSERT INTO TBL_Priprema_GROB(StatusTeseta, StatusPantograf, StatusDispecer, StatusProizvodnja, StatusDokumentacija) VALUES('" & statustestera & "','" & statuspantograf & "''" & statusdispecer & "','" & statusproizvodnja & "',' " & statusdokumentacija & "')"
            comm.ExecuteNonQuery()
        Next
        cn.Close()

0
Accepted
Hristo
Telerik team
answered on 07 Mar 2017, 04:50 PM
Hi Mahir,

Thank you for writing.

In you code snippet I see that you are calling the ToString method on the GridViewRowInfo class. Please note that it will return the type of the row which I am not sure how you would like to use it. 

In case you are trying to access the cells you can iterate the selected rows and their cells respectively:
For i = 0 To Me.RadGridView1.SelectedRows.Count
    Dim row = Me.RadGridView1.SelectedRows(i)
    For j = 0 To row.Cells.Count
        Dim cell = row.Cells(j)
        Dim valueAsString = cell.Value.ToString()
    Next
 
Next

Please also check the following documentation articles showing how the rows and cells can be iterated:
I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Mahir
Top achievements
Rank 1
Answers by
Mahir
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or