Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB 2008 DataGridView

VB 2008 DataGridView

Scheduled Pinned Locked Moved Visual Basic
helpdatabaseoraclequestionannouncement
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Filippo1974
    wrote on last edited by
    #1

    Hi all, I have an issue with a datagrid in VB 2008 Express. I have loaded an Excel file into a datagrid as a preview; now I want to insert the datagrid content into a table in an Oracle DB (tha table have the same fields of the excel file). How ca I do it? I have tried with the following code but doesn't work :(: Using connection As New OleDbConnection(connectionString) Dim adapter As New OleDbDataAdapter() adapter.InsertCommand = New OleDbCommand(queryString, connection) Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter) connection.Open() adapter.Fill(data) adapter.Update(data, tableName) Return data End Using When VB try to execute this command adapter.Fill(data) it crash with vshost error. If I Delete this row the functon works, but I haven't the data into the table. Is there anyone can help me? Many thanks Filippo

    D W 3 Replies Last reply
    0
    • F Filippo1974

      Hi all, I have an issue with a datagrid in VB 2008 Express. I have loaded an Excel file into a datagrid as a preview; now I want to insert the datagrid content into a table in an Oracle DB (tha table have the same fields of the excel file). How ca I do it? I have tried with the following code but doesn't work :(: Using connection As New OleDbConnection(connectionString) Dim adapter As New OleDbDataAdapter() adapter.InsertCommand = New OleDbCommand(queryString, connection) Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter) connection.Open() adapter.Fill(data) adapter.Update(data, tableName) Return data End Using When VB try to execute this command adapter.Fill(data) it crash with vshost error. If I Delete this row the functon works, but I haven't the data into the table. Is there anyone can help me? Many thanks Filippo

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      What is the error message?

      F 1 Reply Last reply
      0
      • D dan sh

        What is the error message?

        F Offline
        F Offline
        Filippo1974
        wrote on last edited by
        #3

        "vshost.exe has stopped working" and the application crash

        F 1 Reply Last reply
        0
        • F Filippo1974

          "vshost.exe has stopped working" and the application crash

          F Offline
          F Offline
          Filippo1974
          wrote on last edited by
          #4

          Hi tried also to cicle into the rows/cols into the Datase with the following instruction Dim iRow As Integer Dim iCols As Integer Dim sriga As String For iRow = 0 To dgvPreview.RowCount For iCols = 0 To dgvPreview.ColumnCount If Len(sriga) = 0 Then sriga = dgvPreview.Rows(iRow).Cells(iCols).Value.ToString Else sriga = sriga & ", " & dgvPreview.Rows(iRow).Cells(iCols).Value.ToString End If Next TextBox2.Text = TextBox2.Text & vbCrLf & sriga TextBox2.Refresh() sriga = "" Next But the finel result is the same:( The Vb crash with the same vshost error Please Help me! I'm going mad!

          S 1 Reply Last reply
          0
          • F Filippo1974

            Hi all, I have an issue with a datagrid in VB 2008 Express. I have loaded an Excel file into a datagrid as a preview; now I want to insert the datagrid content into a table in an Oracle DB (tha table have the same fields of the excel file). How ca I do it? I have tried with the following code but doesn't work :(: Using connection As New OleDbConnection(connectionString) Dim adapter As New OleDbDataAdapter() adapter.InsertCommand = New OleDbCommand(queryString, connection) Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter) connection.Open() adapter.Fill(data) adapter.Update(data, tableName) Return data End Using When VB try to execute this command adapter.Fill(data) it crash with vshost error. If I Delete this row the functon works, but I haven't the data into the table. Is there anyone can help me? Many thanks Filippo

            W Offline
            W Offline
            William Winner
            wrote on last edited by
            #5

            Well, first of all, I don't think you're understanding how ADO.Net works. I suggest starting here: Overview of ADO.NET[^]. The InsertCommand that you are creating is used to run a SQL Insert...or in other words to insert a record into a database. And, the InsertCommand is only used when running an Update where records are marked as added or if you say InsertCommand.ExecuteNonQuery(). If you are trying to fill a table, you need to change the way you are setting up the table. I suggest looking at: OleDBDataAdapter Class[^] You want to change it to provide a SelectCommand. Generally, you do this like:

            newDataAdapter = New OleDb.OleDbDataAdapter(sql, connectionString)

            newDataAdapter.Fill(ProjectDS, "ProjectInfo")

            I would say you clearly haven't looked at how to use ADO.NET and you need to start there.

            1 Reply Last reply
            0
            • F Filippo1974

              Hi all, I have an issue with a datagrid in VB 2008 Express. I have loaded an Excel file into a datagrid as a preview; now I want to insert the datagrid content into a table in an Oracle DB (tha table have the same fields of the excel file). How ca I do it? I have tried with the following code but doesn't work :(: Using connection As New OleDbConnection(connectionString) Dim adapter As New OleDbDataAdapter() adapter.InsertCommand = New OleDbCommand(queryString, connection) Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter) connection.Open() adapter.Fill(data) adapter.Update(data, tableName) Return data End Using When VB try to execute this command adapter.Fill(data) it crash with vshost error. If I Delete this row the functon works, but I haven't the data into the table. Is there anyone can help me? Many thanks Filippo

              W Offline
              W Offline
              William Winner
              wrote on last edited by
              #6

              One more thing...you need to make sure to close your connection before returning. It's bad practice to keep it open. I also hope you're creating the DataTable in your function because if it's a global variable, then why are you returning it? And if it's not accessible outside whatever class you're using, why are you making it a global variable?

              1 Reply Last reply
              0
              • F Filippo1974

                Hi tried also to cicle into the rows/cols into the Datase with the following instruction Dim iRow As Integer Dim iCols As Integer Dim sriga As String For iRow = 0 To dgvPreview.RowCount For iCols = 0 To dgvPreview.ColumnCount If Len(sriga) = 0 Then sriga = dgvPreview.Rows(iRow).Cells(iCols).Value.ToString Else sriga = sriga & ", " & dgvPreview.Rows(iRow).Cells(iCols).Value.ToString End If Next TextBox2.Text = TextBox2.Text & vbCrLf & sriga TextBox2.Refresh() sriga = "" Next But the finel result is the same:( The Vb crash with the same vshost error Please Help me! I'm going mad!

                S Offline
                S Offline
                Sebastian Br
                wrote on last edited by
                #7

                Try the following: For iRow = 0 To dgvPreview.RowCount - 1 For iCols = 0 To dgvPreview.ColumnCount - 1 (Note the additional "- 1" at the end of the lines) Maybe it is also helpful for your further devolpments to use try-catch-blocks, to handle exceptions. Normally the Exception itself contains several useful information, which could help you to identify the error's position and circumstances.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups