Solved

save file to database vb.net vs2005

Posted on 2007-04-09
3
283 Views
Last Modified: 2013-12-17
I have the prototype of a screen where someone can browse for a file.  It is supposed to be imported into the table below.  I plan to use a dataset built in the designer.  How do I save the file to the db?

CREATE TABLE [Banks].[tblBankAttachments](
      [BankAttachmentGUID] [PCA].[UDT_GUID] NOT NULL,
      [BankGUID] [PCA].[UDT_GUID] NOT NULL,
      [Filename] [varbinary](50) NOT NULL,
      [Filedescription] [nchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [FileSize] [int] NOT NULL,
      [FileText] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [CreatedOn] [datetime] NOT NULL,
      [CreatedBy] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
 CONSTRAINT [PK_tblBankAttachments] PRIMARY KEY CLUSTERED
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
ID: 18877670
What type of database are you trying to write to?

Here is an example of how you can do it with SQL:

Assuming that you have a strongly typed dataset created with 1 table named "Banks"
Dim cn As New SqlClient.SqlConnection("Your Connection String")

Dim da As New SqlClient.SqlDataAdapter()
da.InsertCommand = New SqlClient.SqlCommand("CommandTextOrStoredProcedure", cn)

'Use whichever CommandType is appropriate for you
da.InsertCommand.CommandType = CommandType.StoredProcedure
'da.InsertCommand.CommandType = CommandType.Text

With da.InsertCommand.Parameters
     .Add(New SqlClient.SqlParameter("@BankAttachmentGUID", SqlDbType.Udt, 0, "BankAttachmentGUID"))
     .Add(New SqlClient.SqlParameter("@BankGUID", SqlDbType.Udt, 0, "BankGUID"))
     .Add(New SqlClient.SqlParameter("@Filename", SqlDbType.VarBinary, 50, "Filename"))
     .Add(New SqlClient.SqlParameter("@Filedescription", SqlDbType.NChar, 255, "Filedescription"))
     .Add(New SqlClient.SqlParameter("@FileSize", SqlDbType.Int, 0, "FileSize"))
     .Add(New SqlClient.SqlParameter("@FileText", SqlDbType.VarChar, 8000, "FileText"))
     .Add(New SqlClient.SqlParameter("@CreatedOn", SqlDbType.DateTime, 0, "FileText"))
     .Add(New SqlClient.SqlParameter("@CreatedBy", SqlDbType.NVarChar, 30, "CreatedBy"))

End With

'Update Command
da.UpdateCommand = New SqlClient.SqlCommand("InsertCommandTextOrStoredProcedure", cn)

'Whichever is appropriate
da.UpdateCommand.CommandType = CommandType.StoredProcedure
'da.UpdateCommand.CommandType = CommandType.Text

With da.UpdateCommand.Parameters
     .Add(New SqlClient.SqlParameter("@BankAttachmentGUID", SqlDbType.Udt, 0, "BankAttachmentGUID"))
     .Add(New SqlClient.SqlParameter("@BankGUID", SqlDbType.Udt, 0, "BankGUID"))
     .Add(New SqlClient.SqlParameter("@Filename", SqlDbType.VarBinary, 50, "Filename"))
     .Add(New SqlClient.SqlParameter("@Filedescription", SqlDbType.NChar, 255, "Filedescription"))
     .Add(New SqlClient.SqlParameter("@FileSize", SqlDbType.Int, 0, "FileSize"))
     .Add(New SqlClient.SqlParameter("@FileText", SqlDbType.VarChar, 8000, "FileText"))
     .Add(New SqlClient.SqlParameter("@CreatedOn", SqlDbType.DateTime, 0, "FileText"))
     .Add(New SqlClient.SqlParameter("@CreatedBy", SqlDbType.NVarChar, 30, "CreatedBy"))

End With

da.Update(YourDataSet.Banks)     'Banks is the name of the table in the dataset

Hope that is helpful.
0
 

Author Comment

by:jackjohnson44
ID: 18878421
thanks,

sql, but how do I get a file into the variable or check the size?

If I start with a file browse dialogue, where do I go from there?
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 18884984
What type of a data file are they opening up?  A CSV (comma separated value) file, XML, a TXT file, etc?

0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question