VB 2008 DataGridView
-
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
-
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
-
"vshost.exe has stopped working" and the application crash
-
"vshost.exe has stopped working" and the application crash
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!
-
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
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, theInsertCommand
is only used when running an Update where records are marked as added or if you sayInsertCommand.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.
-
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
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?
-
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!
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.