Question about Microsoft Computers & Internet

1 Answer

Use vb.net and access

I m Trying to insert picture into access database using oledb parameters but it will not add the picture in access database
the Code like this
Dim FileName As String
Dim FileStream1 As System.IO.FileStream
Dim FileInfo1 As System.IO.FileInfo
Dim o As System.IO.FileStream
Dim sr As System.IO.StreamReader
Dim gifFile As String
Console.Write(p1)
gifFile = Console.ReadLine
On Error Resume Next
o = New System.IO.FileStream(p2, IO.FileMode.CreateNew)
On Error Resume Next
sr = New System.IO.StreamReader(o) Dim FileByteArray(o.Length - 1) As Byte
o.Read(FileByteArray, 0, o.Length)
Dim Con As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Project\WindowApplication1\Parana.mdb")
Dim Sql As String = "INSERT INTO DRAWING (D_A,FileSize) VALUES (?,?)"
Dim Cmd As New System.Data.OleDb.OleDbCommand(Sql, Con)
Cmd.Parameters.Add("@D_A", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
Cmd.ExecuteNonQuery()
Console.Write(p1)
here p1 and p2 is string variable thet contain file path.
What is the problem inthis code,
plz, reply me as soon as possible
b'cos i m working on this project it's my big problem for developing the software.

thanks,
regards
from
manisha

Posted by on

1 Answer

  • Level 1:

    An expert who has achieved level 1.

  • Contributor
  • 3 Answers

Imports System
Imports System.IO
Imports System.Data
Public Class SaveImage
Shared Sub main()
Dim o As System.IO.FileStream
Dim r As StreamReader
Dim gifFile As String
Console.Write("Enter a Valid .Gif file path")
gifFile = Console.ReadLine
If Dir(gifFile) = "" Then
Console.Write("Invalid File Path")
Exit Sub
End If
o = New FileStream(gifFile, FileMode.Open, FileAccess.Read, FileShare.Read)
r = New StreamReader(o)
Try
Dim FileByteArray(o.Length - 1) As Byte
o.Read(FileByteArray, 0, o.Length)
Dim Con As New _ System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data
Source=Test.mdb")
Dim Sql As String = "INSERT INTO images (Pic,FileSize) VALUES (?,?)"
Dim Cmd As New System.Data.OleDb.OleDbCommand(Sql, Con)
Cmd.Parameters.Add("@Pic", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
Cmd.Parameters.Add("@FileSize", System.Data.OleDb.OleDbType.VarChar, 100).Value = o.Length
Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Catch ex As Exception
Console.Write(ex.ToString)
End Try
End Sub
End Class

Posted on Jul 17, 2008

  • keshav sambyal Jul 17, 2008

    --- Insert Image in Ms-Access ----

    objConnection = New OleDbConnection(objConnectionString)
    objConnection.Open

    Dim content As Byte() = ReadBitmap2ByteArray(ImagePath)

    SqlQuery = "Update ImgTable Set Img=? Where ImgTableID = 1"

    Dim objInsert As OleDbCommand = New OleDbCommand(SqlQuery, objConnection)

    Dim objParam As OleDbParameter = objInsert.Parameters.Add("@Barcode", OleDbType.Binary)

    objParam.Value = content
    objParam.Size = content.Length

    objInsert.ExecuteNonQuery

    objConnection.Close


×

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1 Answer

How to make the library managment project with VB.Net & using MS Access as for database.& please help me out what code should I use for making that project?


firstly you have to create a database and in that you have to create tables as per your requirement.
secondly, create forms in vb and connect the database, as per your requrement. it is not possible to give all the codes. use some e-books.

Nov 19, 2009 | Computers & Internet

1 Answer

How to insert datepicker value in access with use of C#


1.U have to create one acess database .
2 create connection to database using odbc or oledb connection.
3.Write one insert query.
4 execute that query.
5.close the connection

Nov 16, 2009 | Microsoft Visual Basic .NET Standard 2003...

1 Answer

Getting "Unspecified Error" While Opening an Excel File by using OLEDB Connection. I am Using Follwing Code to Open the Excel File. string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data...


Hello, you are probably using an incorrect connection string.

Usually you can use a datasource (such as Access Database) directly in an excel document. If that is what you are trying to accomplish here check out the following sites:
Plug into your data Connecting Excel to an Access database Office Blogs
OR:
Connect an Access database to your workbook

If you are writing software application, from within Visual Studio (depending on the version) go to the left-hand side bar to "Server Explorer" -> "Add Data Connection" -> Click on the "Change" button of the Data Source part and select the appropriate Access Data Source -> Click the "Advanced" button.

After that, you will see in the bottom textbox, the appropriate connection string for the JET.OLEDB Connection Provider.

This is shown in the image below:

fews-khtxegu4lrzhmquqt25la0x1-4-0.png Alternatively, you can find more information about your connectivity string in the link below:
https://www.connectionstrings.com/microsoft-jet-ole-db-4-0
For usage of an oledb connection object you can find info here --> https://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection(v=vs.110).aspx

Mar 30, 2017 | Microsoft Computers & Internet

1 Answer

Retrieving acess data which is password protected thru VB


You will need to use a connection string. But - before you can configure the string correctly, I'd need to know how the data is stored (Access, SQL, ODBC, etc). You can find examples online. Just know that you are looking for "Connection String." Here's two examples:
1. For MS Access (Jet files):
' Set up the connection string.
m_strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDestDBPath & ";" & _
"Jet OLEDB:Engine Type=5" ' NOTE: Use Type=5 for Jet 4.x.

2. For SQL database:
g_strADOConn = "Provider=SQLOLEDB;" & _
"Data Source=SERVER_NAME;" & _
"Initial Catalog=DATABASE_NAME;" & _
"User ID=mssql_userid;" & _
"Password=mssql_password;"

Apr 22, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

What is the compatible database for visual basic 6.0?


Microsoft Access uses the Jet Engine. In VB 6, you can create a data connection using ODBC or OLE DB. Here is an example of OLE DB:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\YourAccessDB.mdb;User Id=;Password=;" Good luck

Mar 09, 2009 | Microsoft Press MS Access 2000 and Visual...

1 Answer

How to connect vb with ms access


se Adodc OR Even better.. ADODB. for this you need to get MDAC fromMicrosoft free download.(check under project_References- Microsoft DataActiveX objects.. the current no is 2.8. if it is not there download invb directory.

next, you can learn about creating a DSN from control panel, ODBC. onceyou learn this, connection becomes a piece of cake. get some free vbtutoriasl from WWW.

then

you need to use DAO or ADO to connect to the database. better study both but since ADO is current, i am showing that code.
under Menu Project_References, put a check mark on Microsoft ActiveXData Objects latest version (though it works for all, currently 2.8with sp pack 1 ).

at the general declarations:
dim conn as adodb.connection, rec as adodb.recordset, esql as string,esql1 as string
Private Function connect()
Set rec = New ADODB.Recordset
Set conn = New ADODB.Connection
esql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "D:VBDesigndhana2.mdb" & ";Persist Security Info=False"
'here you put the correct path of your mdb file. and check if you have jet 4.0

conn.Open (esql), , , 0
End Function

private sub form_Load()
connect
end sub
and for adding records:
say let us say you have 3 fields. then have 3 textboxes and 1 command button on the form.

private command1_click()
esql1="select * from Yourtablename"
rec.open(esql1),conn,, adOpenDynamic, adLockOptimistic
rec.AddNew
rec.Fields(0) = text1.Text
rec.Fields(1) = Text2.text
rec.Fields(2) = text3.text
' you need to check if in your access table design you have Allowed Zero length .. set it to Yes for all text fields.
rec.update
if not rec.eof then rec.movenext
rec.close
conn.close
set conn to nothing
end sub

this will add new records to access table from VB.
' for picture store the full path of the path and the picture file nameint the text field. and in the picturebox of VB form for viewingrecords again you need ADO or ADODC and here you code:picture1.picture=Loadpicture(rec.fields(3) ' depending on where thepicture field is located. you need to make a few trials.
under Menu Project_References, put a check mark on Microsoft ActiveXData Objects latest version (though it works for all, currently 2.8with sp pack 1 ).

at the general declarations:
dim conn as adodb.connection, rec as adodb.recordset, esql as string,esql1 as string

Private Function connect()
Set rec = New ADODB.Recordset
Set conn = New ADODB.Connection
esql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "D:VBDesigndhana2.mdb" & ";Persist Security Info=False"
'here you put the correct path of your mdb file. and check if you have jet 4.0

conn.Open (esql), , , 0
End Function

private sub form_Load()
connect
end sub

and for accessing records:

private command1_click()
esql1="select * from Yourtablename where id =" & val(text1) ' for integers

esql1="select * from Yourtablename where name=" & "'" & text1 & "'" ' for string

rec.open(esql1),conn, adOpenstatic, adLockreadonly

label1.caption =rec.Fields(0)
label2.caption= rec.Fields(1)
label3.caption= rec.Fields(2)
' you need to check if in your access table design you have Allowed Zero length .. set it to Yes for all text fields.

rec.close
conn.close
set conn to nothing
end sub


' similarly there are routines to ADD, Delete, Edit, View etc.

Feb 26, 2009 | Computers & Internet

2 Answers

How to access database to vb.net


look this website:
http://www.codeproject.com/
you can get all your answers about .NET and VB there by a simple search
enjoy it!
good luck

Feb 19, 2009 | Microsoft Visual Basic .NET Step By Step...

1 Answer

How to add columns(Vertical) only in Msflexgrid from database table using VB.


you have to open your current project in VB then go to "add references" (its somewhere in the menu bar) then go find microsoft acess and add it as a reference. then go to object browser and you'll find all the functions you need to interface between your project in VB and MS Access.

good luck !!!

Dec 30, 2008 | Computers & Internet

1 Answer

Code for find the Ms access database size using visual basic


The way to get the database size is to point to the directory that the database is do a DIR statement with an output to a file as in DIR payroll.mdb>dbsize.txt and then read from the text file, the first field of the second line being the name (which you really don't need) then the size value of the database.

To import the text files using VB 8 use

'Imports System.Data.OleDb Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\path\filename.mdb") Dim cmd As New OleDbCommand("SELECT * INTO [import] FROM [Text;Database=d:\path;Hdr=No].[dbsize.txt]", conn) conn.Open() cmd.ExecuteNonQuery() conn.Close()

Nov 10, 2008 | Microsoft Office Standard for PC

1 Answer

MS Access and ASP.net application


You probably need to be inserting the value of a text object (ie, a String) , not the object itself. In VB.NET, a String object is an actual, not unlike a Java String object. In "classic" VB, a String object isn't really handled by the interpreter as an object in the C# / Java sense, so it can be referred to directly without resolving the value via a method call. So attempting to insert an object reference into a database field from C# code will probably not work unless the database knows to call toSting() on the object, which I am 99.99999% sure it cannot (depends on the database-- in this case Access, and more particularly, what version you are using, and if there is any .NET framework interoperability).

Calling myString.toString() though returns a String object in C#, so using that is likely not going to work. What you may need to do is return a character array using the 'chars' and 'length' properties of the C# String object.

Finally, after all this, your problem could be a lot simpler: the value(s) you are trying to insert may not be right for the field-- check the length of the values being inserted, etc. Use .trim() to eliminate leading and trailing whitespace, for example. If you post your INSERT statement and an example of the data you are using, I may be able to tell you more. Also, you are in ASP.NET and data transfer from web containers to Access databases is notoriously bedeviled work.

Mar 07, 2008 | Computers & Internet

Not finding what you are looking for?
Computers & Internet Logo

Related Topics:

293 people viewed this question

Ask a Question

Usually answered in minutes!

Top Microsoft Computers & Internet Experts

micky dee

Level 3 Expert

2642 Answers

Les Dickinson
Les Dickinson

Level 3 Expert

18375 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

Are you a Microsoft Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...