|
xlsApp1.workbooks give you all the info about the open files by your program and others(manualy)
|
|
|
|
|
I need a help, plzzzzzz help me .Iam doing this for last 20 days and everytime i'm getting typical errors.
plz anyone of u, specially MVP Persons help me.
I want to save an image in my access table, iam using vb.net2008 as frontend. there are 10 fields of text, 1 of combobox and 1 of picture box.Its just like a query form along with the phto which i want to save in my access database.
YOur immediate help would be appreciable.
Byee
mirza
|
|
|
|
|
mirzamujib wrote: YOur immediate help would be appreciable.
IMMEDIATE help ? Because we owe you or something ?
This is a trivial task, widely reported on the internet. What have you done to try to solve it ? What errors are you getting ? If you ask questions properly, you will get better answers.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
hello Mr.Graus
Actually i really got fedup by searching the procedure of "Saving an image in access" using vb.net2008.
i'm attaching here my code,please find it where iam going error.
Try
Dim conn As New OleDbConnection
Dim cmd As New OleDbCommand
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Contacts3\mycontacts.mdb;"
conn.Open()
cmd = conn.CreateCommand
cmd.CommandText = "Insert into mycontactstab(TextBox1.Text,TextBox2.Text,TextBox3.Text,TextBox4.Text,picturebox1.image) values(@Email1,@Email2,@Website,@Notes,@Image)"
Try
Dim imgbytearray As Byte
Dim stream As New MemoryStream
Dim bmp As New Bitmap(stream)
bmp.Save(stream, ImageFormat.Jpeg)
imgbytearray = stream.ToString() ''''might be here i'm going wrong'''''
stream.Close()
cmd.Parameters.AddWithValue("@Email1", TextBox1.Text)
cmd.Parameters.AddWithValue("@Email2", TextBox2.Text)
cmd.Parameters.AddWithValue("@Website", TextBox3.Text)
cmd.Parameters.AddWithValue("@Note", TextBox4.Text)
cmd.Parameters.AddWithValue("@Image", imgbytearray)
If DirectCast(cmd.ExecuteNonQuery(), Integer) > 0 Then
Return
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
'Return
End Try
conn.Close()
cmd.Dispose()
conn.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
|
|
|
|
|
mirzamujib wrote: cmd.CommandText = "Insert into mycontactstab(TextBox1.Text,TextBox2.Text,TextBox3.Text,TextBox4.Text,picturebox1.image) values(@Email1,@Email2,@Website,@Notes,@Image)"
Your seriously need to pickup a beginners book on VB.NET. This single line has a very serious problem in it stems from a lack of understanding of how strings work and how SQL works.
mirzamujib wrote: ''''might be here i'm going wrong'''''
No, you're going wrong in just about that entire code snippet you posted. Seriously, you need to get the basics of the language down first before trying something like this.
|
|
|
|
|
Christian Graus wrote: "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
LOL. Reading some of the questions gives me a headache.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
1st, let me start by saying that saving an image in Access is a bad idea.
It will be a memory hog and Access only can hold about 1 gb of data.
What you should do is just offer a path to the image and allow that to load when needed. What are your "Typical" errors?
|
|
|
|
|
Hello,
Ya that wil be better if i save a path instead of a picture itself..thnx for ur idea but iam very new to vb.net, wil u please help me to get the code to save the path of an image...
Thnx mindserve....
|
|
|
|
|
Look at
system.io.file
system.io.path
system.io.directory
namespaces
You should be able to figure it out
(saving a path to db is just saving a string)
|
|
|
|
|
Hello Tom
here i''m copying my code,plz have a look on it and suggest me how should i write code for my insert command.
Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Contacts3\mycontacts.mdb;Persist Security Info=False"
Dim con As New OleDbConnection(connectionstring)
Dim cmd as new OleDbCommand
Try
con.Open()
Dim str As String = "Insert into mycontactstab values ( '" & TextBox6.Text & "','" & TextBox4.Text & "','" & TextBox7.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "',PicureBox1.image)"----(here wht should i write as i took picture box to retrieve and save an image)-----
Dim cmd As New OleDbCommand(str, con)
If cmd.ExecuteNonQuery() Then
|
|
|
|
|
0) Read up on 'SQL injections' (google it)
1) as to your question. A picturbox has a property 'imagelocation' this should be the path where the image is loaded from.
Better practice tho is to copy the image to folder that you control and only save the imagename. (since you have the folder path (keep it in a parameter or so) you can always reload the image)
Why? If you allow the user to pick an image from his folders they can delete that picture afterwards, breaking your data.
|
|
|
|
|
thnxs Tom for ur knowledgable reply.Now i'm not getting an error on my insert command to which i changed for picturebox1.imagelocation.
Dim str As String = "Insert into mycontactstab values ( TextBox7.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & PictureBox1.ImageLocation & "')"
Kindly let me knw the syntax to save the image address in my access database and how can i retrieve it.
I'l be thankful for u....
Mirza
|
|
|
|
|
from what I can see this should work. (sql injunctions aside)
Are you getting errors?
Basically if you want to save the path of the image you just save it as a string (like your doing with the textbox values)
picturebox1.imagelocation gives you that string
This doesn't mean your are saving the image itself only where it is located on the harddrive.
When you want to show the image again you need to retrieve this path and set the picturebox1.imagelocation to this path.
Like I said before this is not the best way to do it, better would be to copy the image to a safe location (one where the user can't delete it) and save the image name (file name).
Play with it a bit, research the namespaces I gave in my first reply.
And really look at SQL injunctions it will save you from a lot of trouble.
|
|
|
|
|
|
Thanks Tom for your knowledgable information...now i dont've any error on my insert syntax as shown:
Dim str As String = "Insert into mycontactstab values ('" & TextBox8.Text & "','" & TextBox9.Text & "','" & PictureBox1.ImageLocation & "')"
Kindly let know the syntax whch saves the imagepath in my access database and upon clicking retrieve button it should upload my image.
Once Again thnk for your help.
tc
|
|
|
|
|
http://www.dreamincode.net/forums/showtopic53876.htm
It's right here on this forum, or you can google it.
You won't learn if you don't try to play with it on your own.
|
|
|
|
|
Hi,
Its true but iam also much trying to solve this problem but dont knw where i'm lacking behind...The link which u gave above is just to upload an image from database, i need to knw how to save it in a database.anyways thnk u so much for ur valuable help..
|
|
|
|
|
I have source code for you but you have to figure out how to save the path to a database and then it will load the image back.
|
|
|
|
|
iam trying mr.mindserve...
|
|
|
|
|
oK Mr.mindserve...
Thank you...
|
|
|
|
|
Hello mindserve,
I've successfully able to save the path of an image in my database,now iam unable to load the image back, as u said that u'l help me in loading the image back if i figure out how to save the path to a database..
Kindly reply me...am eagerly waiting for ur reply..
plzzzzzzz
|
|
|
|
|
Add two buttons to the form1, one picture box and one label
Follow the code for the names of the controls.
Also add openfiledialog to the application from the toolbox. it is named dlgOpen
Then add this code to the form1
-------------------------------------------
Class Form1
Private Sub lblPhotoFileBefore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblPhotoFileBefore.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
1: lblPhotoFileBefore.Text = ""
2: Photo.Image = Nothing
End Sub
Private Sub ShowPhoto()
1: If lblPhotoFileBefore.Text <> "" Then
2: Try
3: Photo.Image = Image.FromFile(lblPhotoFileBefore.Text)
4: Catch ex As Exception
5: MessageBox.Show(ex.Message, "Error Loading Photo", MessageBoxButtons.OK, MessageBoxIcon.Error)
6: End Try
7: Else
8: Photo.Image = Nothing
9: End If
End Sub
Private Sub btnLoadPhoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadPhoto.Click
1: Try
2: If dlgOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
3: lblPhotoFileBefore.Text = dlgOpen.FileName
4: Call ShowPhoto()
5: End If
6: Catch ex As Exception
7: MessageBox.Show(ex.Message, "Error Opening Photo", MessageBoxButtons.OK, MessageBoxIcon.Error)
8: End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
|
|
|
|
|
Thank you so much!!
|
|
|
|
|
I have an excel template, from this template i copy the worksheet and save it to workbook.
I initially created an excel.application instance
xlsApp1 = CreateObject("Excel.Application")
then , i open this template file
temp = xlsApp1.Workbooks.Open(ExsTemplate & "sheet.xls")
i am presently in debug mode and breakpoint is on the above line.
and right after this i open an excel sheet by double clicking it which is lying in my hard drive. This opens the template file also.
This is the problem. Can u tell me how should i avoid this problem.
|
|
|
|
|
You problem isn't clear. Are you asking for a way to stop someone from opening a file? Because I don't think you can do that. Or are you getting an error because the file has been opened by the user? In which case, what is the error?
|
|
|
|