Could not find installable ISAM while opening excel file with OLE driver - webforms

I am getting a "Could not find installable ISAM" error in the asp.net webform using visual basic. I am using .Net 4.6 framework. I tried different combinations of connection strings and I also tried with a single quote on Extended Properties as many online solutions suggested but the error did not go away. My code is as below:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As OleDbConnection
Dim dta As OleDbDataAdapter
Dim dts As DataSet
Dim excel As String
excel = "C:\Users\ishfaq.babar\Downloads\aaa.xlsx"
'Dim openfiledialog As New OpenFileDialog
'conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties='Excel 12.0;'";")
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ishfaq.babar\Downloads\aaa.xlsx;Extended Properties='Excel 12.0;HDR=YES;Persist Security Info=False'")
dta = New OleDbDataAdapter("select * from [Sheet1$]", conn)
dts = New DataSet
dta.Fill(dts, "[Sheet1$]")
ExcelGridData.DataSource = dta
ExcelGridData.DataBind()
End Sub
i got error on line
dta.Fill(dts, "[Sheet1$]")
Moreover,I have installed both versions of ole drivers x64 and X86 and I had installed ole driver by command line as:
accessdatabaseengine /quiet
accessdatabaseengine_X64 /quiet
Because I was getting error from GUI Installer as:
microsoft.ace.oledb.12.0' provider is not registered on the local machine
ScreenShot of installed drivers is as follows:
OLE Drivers.Installed Access database Engine versions

ERROR has been resolved automatically with no change in code at all. Just after login again to my account after taking a break it runs successfully:
EDIT:
I Put conn.Open() after connection string.
New Code is As Below:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As OleDbConnection
Try
Dim dta As OleDbDataAdapter
Dim dts As DataSet
Dim excel As String
excel = "C:\Users\ishfaq.babar\Downloads\aaa.xlsx"
'Dim openfiledialog As New OpenFileDialog
'conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties='Excel 12.0;'";")
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ishfaq.babar\Downloads\aaa.xlsx;Extended Properties='Excel 12.0;HDR=YES;Persist Security Info=False'")
conn.Open()
'PrintLine('ok')
' conn.Close()
dta = New OleDbDataAdapter("select * from [Sheet1$]", conn)
dts = New DataSet
dta.Fill(dts, "[Sheet1$]")
ExcelGridData.DataSource = dta
ExcelGridData.DataBind()
Catch ex As Exception
conn.Close()
End Try
End Sub
Read data successfully from excel file as below screenshot:
Result of data read from excel file

Related

Datarowcollection cannot be converted to string In visual basic

I am working on a system right now in which When I put some value in my first text box (For eg. A primary key), I want the other textboxes to fetch the related data from my database and automatically get filled with it. I'm working on visual basic. I am new to this. For some Reason, it keeps on telling me that datarowcollection cannot be converted to string. Please help me get his working.
Here is the code:-
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Dim Cn As New SqlClient.SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\admin\Documents\Asset_Manager.mdf';Integrated Security=True;Connect Timeout=30")
Dim StrCmd As String = "Select * from Asset_Master where Asset_Id= '" & txt_allocate_asset_id.Text & "' "
Dim Command As SqlCommand
Dim da As SqlDataAdapter
Dim dt As New DataTable
Try
Cn.Open()
Command = New SqlCommand(StrCmd, Cn)
da = New SqlDataAdapter(Command)
Command.ExecuteNonQuery()
da.Fill(dt)
txt_demo_model_no.Text = dt.Rows[0][model_no].ToString()//The error line
Catch ex As Exception
Throw ex
End Try
End Sub

How to retrieve an image from an Access Database in Visual Studio?

I'm trying to retrieve an image stored in an Access Database to a Picturebox.
I'm not very fluent with this language, but my current code is as follows:
Private Sub lstUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstUsers.SelectedIndexChanged
Dim dt As New DataTable
dt = runSQL("Select * from tblUser where UserName = '" & lstUsers.SelectedItem.ToString & "'")
txtForename.Text = dt.Rows(0)(2)
txtSurname.Text = dt.Rows(0)(3)
txtCode.Text = dt.Rows(0)(6)
txtFinish.Text = dt.Rows(0)(7)
Dim data As Byte() = DirectCast(dt.Rows(0)(8), Byte())
Using ms As New MemoryStream(data)
Me.PictureBox1.Image = Image.FromStream(ms)
End Using
End Sub
When I try to run it and I select a username I get the following error message pointing to Image.FromStream(ms):
Parameter is not valid.
Any help would be appreciated.

How to load picture into MS-Access Image control from ADO recordset field?

Using:
MS-Access 2013 SP1 x86
MS-SQL Server 2012 SP1 CU8 x64
Connection via ODBC DSN, SQL Server driver
UpScene Database Workbench Pro v4.4.4 Pro for MS-SQL Server
My Access 2013 application uses SQL Server 2012 as the backend database with ODBC. I'm using VBA/ADO to read/write data to the database.
I have been unsuccessful so far in retrieving an image from the database and assigning it to an image control on an Access form. The image is stored in a SQL Server table (as a VARBINARY(MAX) field.
At the point where I'm assigning the field to the Image control, it gives a runtime error: "Type mismatch". The image stored in the database as a Bitmap image. I tried with Jpeg earlier, but it was the same error. How can this be resolved?
SQL Server table definition and stored procedure definition:
CREATE TABLE dbo.tbPhoto (
row_id Int IDENTITY NOT NULL,
student_id Int NOT NULL,
picture VarBinary(max),
date_updated DateTime NOT NULL,
date_created DateTime NOT NULL,
CONSTRAINT PK_tbPhoto PRIMARY KEY CLUSTERED (
row_id
)
)
Access procedures to retrieve the picture:
Private Sub load_studentdetails(AStudentID As Integer)
On Error GoTo errhnd
objStudent.GetStudentDetails AStudentID, StudentDetailsRS
Set Me.fmStudentReg_DtlA.Form.Recordset = StudentDetailsRS
' Me.fmStudentReg_DtlA.Form.Requery
objStudent.GetStudentPicture AStudentID, Me.fmStudentReg_DtlA!imgStudentPic
Exit Sub
errhnd:
MsgBox "Error: " & Err.Description
End Sub
Public Sub GetStudentPicture(AStudentID As Integer, ByRef APicture As Image)
On Error GoTo errhnd
Dim rs As New ADODB.Recordset
Set cmd.ActiveConnection = GetDBConnection
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "dbo.StudentPicture_S"
cmd.Parameters.Refresh
cmd(1) = AStudentID
rs.CursorLocation = adUseClient
rs.Open cmd
Set APicture = rs("picture") '<-----Raises the error: "Type mismatch"
Exit Sub
errhnd:
MsgBox "Error: " & Err.Description
End Sub
Since you are already using an ADODB.Recordset I would suggest that you use an ADODB.Stream object as an intermediary. I just tried the following code and it worked for me:
Option Compare Database
Option Explicit
Private Sub cmdGetPhoto_Click()
Dim cdb As DAO.Database
Dim con As ADODB.Connection, rst As ADODB.Recordset, stm As ADODB.Stream
Set cdb = CurrentDb
Set con = New ADODB.Connection
con.Open Mid(cdb.TableDefs("dbo_Clients").Connect, 6)
Set rst = New ADODB.Recordset
rst.Open "SELECT Photo FROM Clients WHERE ClientID=1", con, adOpenStatic, adLockOptimistic
Set stm = New ADODB.Stream
stm.Type = adTypeBinary
stm.Open
stm.Write rst("Photo").Value ' write bytes to stream
stm.Position = 0
Me.Image0.PictureData = stm.Read ' load bytes into Image control on form
stm.Close
Set stm = Nothing
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing
Set cdb = Nothing
End Sub

How to connect a database to crystal report at run time?

I am developing winform application in vb6. I am using crystal report 4.6. I have created a crystal report which shows all data from a table (MS Access). And I unchecked save data with report and i saved the report. I just want to invoke it in application. So I included the component CrystalReportControl in my application. Now i want to set the records to be displayed in the report. The records are selected according to the user input to the text box.
Records are retrived from the database is done in following code.
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
Set conn = New ADODB.Connection
conn.Open "provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path &"\faculty.mdb"
Set rs = New ADODB.Recordset
rs.Open "select * from facultydetails where eid=1234", conn, adOpenDynamic, adLockPessimistic
CrystalReport1.ReportFileName = App.Path & "\faculty.rpt"
Set CrystalReport1.DataSource = rs
CrystalReport1.Action = 1
End Sub
Gives an error for the line: Set CrystalReport1.DataSource = rs :
as Property is write-only.
Tell me how the records of the report can be dynamic? Plz help me...
Instead of
Set CrystalReport1.DataSource = rs
do
CrystalReport1.DataSource = rs
EDIT:
Take a look at the following example and see if that will help you:
'CrystalReport1 is the name of the dsr file
Dim Report As New CrystalReport1
Dim cdoRowset As CrystalDataObject.CrystalComObject
Dim varArray() As Variant
'Open ADO Connection
Set m_cnAdo = New ADODB.Connection
m_cnAdo.ConnectionString = "DRIVER={SQL Server};UID=[UserID];PWD=[Password]" _
& ";SERVER=[Server];DATABASE=[Database]"
m_cnAdo.Open
Dim rsAdo As ADODB.Recordset
Dim cmdAdo As ADODB.Command
'Using Embedded Query
Set cmdAdo = New ADODB.Command
Set rsAdo = New ADODB.Recordset
cmdAdo.ActiveConnection = m_cnAdo
cmdAdo.CommandText = "SELECT * FROM Table WHERE Param = " & lngParam1
cmdAdo.CommandType = adCmdText
Set rsAdo = cmdAdo.Execute
Report.Database.SetDataSource rsAdo, 3, 1

Multiple-step OLEDB Error for SQLSERVER.CE.OLEDB.3.5 Connection

I am trying to connect to a SQL Server Compact Edition .sdf file with following connection string;
connMRC.ConnectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=" & App.Path & "\Freeweigh.sdf;"
I get the following error everytime I try running an SQL command or opening a recordset:
Multiple-step OLE DB generated errors. Check each OLE DB status value, if available. No work was done.
I am using VB 6.0 and SQL Server Compact 3.5 SP2
Here's the code:
Public Sub opnConnectionC()
'Code for opening the ADO Connection
chkConn = connMRC.State
If chkConn = adStateClosed Then
connMRC.ConnectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=" & App.Path & "\Freeweigh.sdf;"
connMRC.Open
End If
End Sub
Public Sub opnRecordsetC(rsOpen As Recordset)
'Code for opening the ADO Recordset
chkRs = rsOpen.State
If chkRs = adStateClosed Then
rsOpen.Source = strSQLC
rsOpen.CursorType = adOpenDynamic
rsOpen.LockType = adLockOptimistic
rsOpen.ActiveConnection = connMRC
rsOpen.Open
End If
End Sub
Private Sub tmrUpload_Timer()
Dim cmdUpload As New ADODB.Command
Dim rsFetch As New ADODB.Recordset
Call opnConnectionC
strSQLC = "SELECT Product FROM VehicleWeights"
Call opnRecordsetC(rsFetch)
rsFetch.MoveFirst
MsgBox (rsFetch.Fields("Product").Value)
Call clsConnectionC
End Sub
You can only open a forward only, read only recordset

Resources