Attachments & SQL Database

C

Colin

Hello,

I have a form that I have designed to submit to an SQL Database. What I
would like to know is, is there anyway to attach a file (such as a word doc,
or text file) to the form and have that document save to the SQL Database
when the user clicks submit?
 
S

Sandeep

Hi Colin

This code writen in c# code

string connStr ="server=Your system number;" + "integrated security=SSPI;" +
"database= Your database name";
byte []buffer =
Encoding.Unicode.GetBytes(thisXDocument.DOM.selectSingleNode("/my:myFields/my:field4").text);

SqlConnection conn = new SqlConnection(connStr);
string insert= "insert into employee2 values (@id,@photo)";
SqlCommand cmd=new SqlCommand (insert,conn);
cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Char)).Value =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1").text;
cmd.Parameters.Add(new SqlParameter("@photo",SqlDbType.Image)).Value = buffer;
conn.Open ();
cmd.ExecuteNonQuery ();
conn.Close ();

I hopr this will help U
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top