|
All you're doing is saving a stream of bytes to the database, just like saving an image file. Every file is nothing but a stream of bytes.
' This is array is holding the contents of your file.
Dim fileContents() As Byte
.
.
.
myConnection = New SqlConnection(CONNECTION_STRING)
Dim myCommand As New SqlCommand("INSERT INTO someTable (FileData) VALUES (@Image)", myConnection)
Dim myParameter As New SqlParameter("@Image", SqlDbType.Image, fileContents.Length)
myParameter.Value = fileContents
myCommand.Parameters.Add(myParameter)
myConnection.Open()
myCommand.ExecuteNonQuery()
|
|
|
|
|
Thanks again,
I am using Vb.net(Visual Studio) and SqlExpress where I am using Dataset and TableAdapter.
I just need to click on a command to open the directory, select the file and load it or the path of it into the richtextbox and the savecommand_click() save everything..
On read, readcommand_click() read the file in its format and not being able to edit the document.
thanks
|
|
|
|
|
...and...so, what's the question? I just showed you how to save data to an SQL Server. I have no idea what you're asking now...
|
|
|
|
|
Hi Dave,
The question is not actually saving the information. My question is how to open the folder, retrieve .doc, .txt file, like you will do with an image.
thanks
|
|
|
|
|
Wait, wait, wait... You've already got the hard part done, but can't manage the easy part?
You're looking for the OpenFileDialog in the Toolbox. It'll give you the filepath that the user selected. After that, just tell the RichTextBox what the file path is.
What this tells me is that you've been copying 'n pasting code from all over the web looking for something that does what you want it to do. Correct?
|
|
|
|
|
Hi,
back to my very first question, I can get to the folder, when selecting the file, it throws an exception because of image type record..this column should be of image type since on other occasion scanned document will be inserted there.
Hope you understand me now.
thanks alot
|
|
|
|
|
This doesn't make any sense. Are you saying that you want a "scanned image" of the Word, or some other, document, page-by-page??
|
|
|
|
|
The word document can be on a USB to upload or if only a hard copy exists then the hard copy can be scanned to upload.
thanks
|
|
|
|
|
OK, that doesn't answer my question.
|
|
|
|
|
Hi,
here is the cenario:
a form will capture user informations. One richtextbox is for loading a grievance letter which can be a soft copy or a hard copy. if it is a hard copy, it will be first scanned and placed in a folder. Then the application will load it from the folder.
if it is a soft copy, meaning from a USB Flash drive, the app will get it from there.
Hope I am clearer now
thanks
|
|
|
|
|
So? What's so hard about an OpenFileDialog?? What's difficult about calling the RichTextBox's LoadFile method??
|
|
|
|
|
Hi Dave,
Can you shed some light on this?
Dim docs as System.Drawing.Image
ME.OpenFileDilogue.ShowDialog()
docs=System.Bitmap.Drawing.FromStream(Me.OpenFileDialog.OpenFile,True)
Me.PictureBox.Image= docs
My problem is that firstly in the table, the record is of type image
secondly, file that i am selecting is not an image therefore the file cannot be loaded.
I tried to have the record type as bytes and use it as Filestream. No luck..
Maybe you can guide me
Thanks
|
|
|
|
|
waner michaud wrote: My problem is that firstly in the table, the record is of type image
"Image" in the database means any blob of binary data, not a picture.
The first line of code in your snippet is garbage. It refers ONLY to pictures or drawings. It can NOT load a Word document, nor a .TXT file, nor an .RTF, or any other non-picture format. And no, there is no class or method in the .NET Framework that will convert these formats into a "picture" of a page.
waner michaud wrote: Maybe you can guide me
I have no idea what you're ultimately trying to do with this code. Are you trying to save a picture of a Word page, or are you trying to save the Word document itself in the database??
|
|
|
|
|
.....
openFileDialog.Filter = "Word Files|*.DOC" ?
|
|
|
|
|
Hardly the point of his problem. This is just one tiny aspect of using the OpenFileDialog. He's got much bigger issue with his design, including the inability to describe the specification of his app, the design, and what he's ultimately trying to do.
|
|
|
|
|
Hi Dave,
I got this issue solved. I have the path of the file saved in a table.
Now what I want to do is when I load this table, I want to click on a command to read this this file in its format.
Let's say if it is a word document, it will launch msword and the file..for that matter any other format..
thanks
|
|
|
|
|
Launch the full path to the document using the Process class. It'll launch the default editor for that document just like you double-clicked the icon yourself.
|
|
|
|
|
I am currently creating a visual studio plugin for my group. When we are trying to add a new item to the database we click add new item button, another window opens. You add the information and press the okay button. Out of no where the application freezes and gives us a window stating that .NET has encountered an error and shuts down giving you the option to restart. I have stepped through the code on various employees computers and it happens to everyone. Any suggestions on a fix???
|
|
|
|
|
Since you haven't given anny information on what's causing the error, nor the error message, there's little to nothing anyone can tell you on how to fix it.
|
|
|
|
|
I stated that the error was ".NET has encountered an error and shuts down giving you the option to restart." That's all the error was. And I also said that the error would happen when trying to add some information into a text box on a window. when pressing the okay button the app would freeze and that window would pop up saying that Visual Studio has to shut down.
|
|
|
|
|
There could be a hundred reasons why this happened. What you do is start TWO Visual Studio sessions. One debugging the library you wrote, then other to run the library as you normally would. Under Debug menu, you'll find "Attach to process". I think you can figure it out from there.
|
|
|
|
|
Thank you but I think we have figured out the issue. Thanks again!
|
|
|
|
|
Hello,
I currently have an application that when running, has to load a lot of data and it takes too much time. The data is coming from a SQL database. I am not very familiar with async and was wondering if there is a way to run the application asynchronously through the
Init() method? Thank you.
|
|
|
|
|
That doesn't make any sense.
Are you asking if you can load the data on a background thread while your application finishes starting up??
|
|
|
|
|
Sorry. I am not very good at trying to explain. But basically my application takes a very long time to load and was looking into trying to load it asynchronously through the Init() method because this method calls the different connection strings. Or could even have it load the data on a background thread like you mentioned, but I am unsure of how this is accomplished.
|
|
|
|