hi there,
I need to upload files to the mdf file in visual studio 2008 standard edition. the database table which takes the file data in to varchar datatype. i convert the data to byte and then save it in a varchar type field.
the code is below for uploading the file data to the mdf file.
try
{
string constr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\awaduge\My Documents\Visual Studio 2008\Projects\FileUploadDelete\FileUploadDelete\FileUploadDelete.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
db.openConnection();
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
string path = @"C:\Documents and Settings\awaduge\Desktop\Code dgv subcontractor.docx";
byte[] bytearr = File.ReadAllBytes(path);
string query = @"Insert into files(filen) values(@file1)";
using (SqlCommand command = new SqlCommand(query, DB.getConnection()))
{
command.Parameters.Add(new SqlParameter("@file1", bytearr));
command.ExecuteNonQuery();
}
}
db.closeConnection();
MessageBox.Show("Successfully aadded");
}
catch (Exception ex)
{
throw ex;
}
but when i get try to get the data in to a msg box there is an error in the code i wrote with, which is shown below
String query = "Select filen From files Where id=1";
SqlCommand command = new SqlCommand(query,DB.getConnection());
db.openConnection();
SqlDataReader reader = command.ExecuteReader();
byte[] bytearr;
while (reader.Read())
{
String a = reader.GetString(0);
for (int i = 0; i < 50; i++)
{
bytearr[i] = BitConverter.GetBytes(bool.Parse(a));
}
// byte[] bytearr = File.ReadAllBytes(a);
MessageBox.Show(bytearr.ToString());
}
db.closeConnection();
how can i modify the above code so that i can view the data of the file that i have uploaded.
thankxxxxxx
appriciate if someone could help me in this
thnaxx in advance