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

Unbound GridView Save to Database

1 Answer 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 05 Jun 2009, 06:44 PM
I have a GridView that I populate manually using OpenFileDialog...

        Dim fname As String = ""

        If (dlgImportClients.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            fname = dlgImportClients.FileName
        End If

        Dim TextLine As String = ""
        Dim SplitLine() As String

        If System.IO.File.Exists(fname) = True Then
            Dim objReader As New System.IO.StreamReader(fname)

            Do While objReader.Peek() <> -1
                TextLine = objReader.ReadLine()

                'need to add false for checkbox column
                TextLine = "False," + TextLine

                SplitLine = Split(TextLine, ",")

                dgvClients.ColumnCount = SplitLine.Count
                dgvClients.MasterGridViewTemplate.AllowAddNewRow = False
                dgvClients.ReadOnly = False
                dgvClients.Columns(0).IsVisible = True

                'if .RowCount = 0 then we are processing the first row
                If dgvClients.RowCount = 0 Then
                    For i = 1 To SplitLine.Count - 1
                        With dgvClients
                            .Columns(i).HeaderText = SplitLine(i).ToString
                            .Columns(i).BestFit()
                        End With
                    Next
                End If
                dgvClients.Rows.Add(SplitLine)
            Loop

            'stupid but the only way I could get the datagridview to populate correctly
            If dgvClients.RowCount > 1 Then
                dgvClients.Rows.RemoveAt(0)
            End If
        Else
            RadMessageBox.SetThemeName("Breeze")
            RadMessageBox.Show("File Does Not Exist")
        End If

I am loading the .CSV file to the GridView so that it can be reviewed, cleaned up, and then imported into Clients table within the customers database.

I'm kinda stumped as to the best way to get the data in the GridView into the database. Could just be a brain fart or I may be going about this totally wrong. Any insight would be greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
Accepted
Victor
Telerik team
answered on 08 Jun 2009, 10:34 AM
Hi Bob,

Thank you for your question. In order to commit data from an unbound RadGridView, you will have to use the SqlCommand.ExecuteScalar method. Please refer to the msdn page on SqlCommand for more information. Do not hesitate to write back if you need assistance with our controls.

All the best,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Bob
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or