DB parameter collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a binary data to write to sql database by using a stored procedure.
What is the syntax for data type passed to the following call for adding the
parameter? What if the data is longer than 8000 bytes?

cmd.Parameters.Add("Data", "data type");
 
Hi,

you can use this code:

SqlCommand com = new SqlCommand();
com.CommandText = "SaveDocument";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@OrigName", SqlDbType.VarChar).Value = this.origname;
SqlParameter param = com.Parameters.Add("@data", SqlDbType.Image);
FileStream file = new FileStream( physicalname, FileMode.Open);
byte[] buff = new byte [ file.Length];
file.Read(buff, 0, Convert.ToInt32(file.Length));
file.Close();
param.Value = buff;
id = Convert.ToInt32( DataProvider.ExecuteScalar( com) );


Note that I'm reading all the file in memory (dont if this is your case) I'm
dealing with small files so I can do this.
 

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

Back
Top