Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

save file to database vb.net vs2005

Posted on 2007-04-09
3
Medium Priority
?
286 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

715 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