System.data.oledb.oledbexception (0x80004005): Cannot Update. Database or Object Is Read-only.
#i
solve cannot update database or object is read only
Posted 09 May 2016 - 01:27 PM
Below are my code, I am getting "cannot update database or object is read merely vb .net" while opening excel file in DataGrid view
Imports System.Data.SqlClient Imports System.Information.OleDb Imports Arrangement.Information Imports Microsoft.Part.Interop Public Class Form1 Dim con As SqlConnection Dim cmd As SqlCommand Dim reader Every bit SqlDataReader Dim da As SqlDataAdapter Dim cn As New OleDbConnection Dim cm As New OleDbCommand Dim value As Byte = Catechumen.ToByte("Be", 16) Individual Sub Button1_Click(sender Every bit Object, due east As EventArgs) Handles Button1.Click Endeavour Dim MyConnection As System.Data.OleDb.OleDbConnection Dim dataSet Every bit System.Data.DataSet Dim MyCommand As System.Data.OleDb.OleDbDataAdapter Me.OpenFileDialog1.FileName = Null If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Me.TextBox1.Text = Me.OpenFileDialog1.FileName End If MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=+ Me.TextBox1.Text +;Excel 12.0 Xml;Readonly=one;HDR=YES") MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection) dataSet = New System.Data.DataSet MyCommand.Make full(dataSet) DataGridView1.DataSource = dataSet.Tables(0) DataGridView1.ReadOnly = False MyConnection.Close() Grab ex As Exception MsgBox(ex.Bulletin.ToString) End Try Finish Sub Finish Grade
This postal service has been edited by andrewsw: 09 May 2016 - 02:05 PM
Reason for edit:: Removed VB.Cyberspace from topic title, it is redundant
#2
Re: solve cannot update database or object is read simply
Posted 09 May 2016 - 02:01 PM
This Source=+ Me.TextBox1.Text + won't insert the text from the TextBox, it needs to exist concatenated to the cord, not inserted directly into it. Note that the chain operator is &, + should not be used for this purpose.
(You should too exist checking that the text from the TextBox is a valid Excel file, with no boosted text.)
Yous are also explicitly setting the connection equally ReadOnly.
connectionstrings
#iii
Re: solve cannot update database or object is read only
Posted 09 May 2016 - 03:05 PM
in this same code will you delight tell me how i can exercise ? i tried just could not make it out
#4
Re: solve cannot update database or object is read only
Posted 09 May 2016 - 04:01 PM
The line below contains the two parts that andrewsw has told you lot how to gear up.
MyConnection = New Organisation.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=+ Me.TextBox1.Text +;Excel 12.0 Xml;Readonly=i;HDR=YES")
When you want to concatenate the text from a TextBox into the middle of a string yous would exercise something like this for case.
"First role of the cord" & TextBox1.Text & "the residue of the cord"
You lot will also observe that you have the ReadOnly ready to i which would be True in the same line (run across below). I would say y'all either need to set it to 0 or just remove the whole part.
...;Readonly=ane;...
Requite it a endeavour once more. If you tin can not get it, and then testify united states of america that line of code afterward you take changed information technology.
#5
Re: solve cannot update database or object is read simply
Posted 09 May 2016 - 08:thirteen PM
I tried as below but no luck
Imports Organization.Data.SqlClient Imports System.Data.OleDb Imports System.Data Imports Microsoft.Office.Interop Public Class Form1 Dim con As SqlConnection Dim cmd As SqlCommand Dim reader As SqlDataReader Dim da As SqlDataAdapter Dim cn Equally New OleDbConnection Dim cm As New OleDbCommand Dim value Equally Byte = Convert.ToByte("Exist", sixteen) Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim MyConnection Every bit System.Data.OleDb.OleDbConnection Dim dataSet As System.Information.DataSet Dim MyCommand Every bit Organization.Data.OleDb.OleDbDataAdapter 'Dim path Every bit String = "TextBox1.Text" Me.OpenFileDialog1.FileName = Cipher If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK So Me.TextBox1.Text = Me.OpenFileDialog1.FileName End If MyConnection = New Organization.Data.OleDb.OleDbConnection("Provider =Microsoft.ACE.OLEDB.12.0;Information Source= & TextBox1.Text & ;Excel 12.0 Xml;HDR=YES") MyCommand = New Organization.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection) dataSet = New Organization.Data.DataSet MyCommand.Fill(dataSet) DataGridView1.DataSource = dataSet.Tables(0) 'DataGridView1.ReadOnly = Simulated MyConnection.Shut() Grab ex As Exception MsgBox(ex.Message.ToString) Stop Effort End Sub End Class
Pls ignore my earlier post. It'south work fine. Thanks for your help. Correct codes are below
Imports System.Data.SqlClient Imports System.Data.OleDb Imports System.Data Imports Microsoft.Function.Interop Public Grade Form1 Dim con As SqlConnection Dim cmd As SqlCommand Dim reader As SqlDataReader Dim da Equally SqlDataAdapter Dim cn As New OleDbConnection Dim cm As New OleDbCommand Dim value Equally Byte = Convert.ToByte("Exist", sixteen) Individual Sub Button1_Click(sender As Object, east As EventArgs) Handles Button1.Click Try Dim MyConnection Every bit Organisation.Information.OleDb.OleDbConnection Dim dataSet As System.Data.DataSet Dim MyCommand Equally Arrangement.Data.OleDb.OleDbDataAdapter 'Dim path As Cord = "TextBox1.Text" Me.OpenFileDialog1.FileName = Nothing If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Me.TextBox1.Text = Me.OpenFileDialog1.FileName End If MyConnection = New System.Data.OleDb.OleDbConnection("Provider =Microsoft.ACE.OLEDB.12.0;Data Source=" & TextBox1.Text & " ;Excel 12.0 Xml;HDR=YES") MyCommand = New Organisation.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection) dataSet = New System.Data.DataSet MyCommand.Fill(dataSet) DataGridView1.DataSource = dataSet.Tables(0) 'DataGridView1.ReadOnly = False MyConnection.Shut() Grab ex Every bit Exception MsgBox(ex.Message.ToString) End Attempt End Sub Cease Grade
Source: https://www.dreamincode.net/forums/topic/393092-solve-cannot-update-database-or-object-is-read-only/
0 Response to "System.data.oledb.oledbexception (0x80004005): Cannot Update. Database or Object Is Read-only."
Post a Comment