Im trying to save a .txt file to my database but i keep on getting the above error, i have tried alot but just cant solve it. Database table=Data. im using SqlServer. fileloc is a string
private void button2_Click(object sender, EventArgs e)
{
try
{
fileloc = textBox1.Text;
byte[] doc = null;
FileStream fs = new FileStream(fileloc, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
doc = br.ReadBytes((int)fs.Length);
string qry = "insert into Data values(@Data)";
if ( con.State != ConnectionState.Open)
con.Open();
cmd = new SqlCommand(qry, con);
cmd.Parameters.Add(new SqlParameter("@Data", (object)doc));
int row = cmd.ExecuteNonQuery();
if (row > 0)
{
MessageBox.Show("Doc Added", "Message");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I did the edit but still getting the same error.
Database Conenction
SqlConnection con = new SqlConnection("Data Source=sochellespencer\\sqlexpress;Initial Catalog=AscottHighSchool;Integrated Security=True");
I SOLVED IT.
I PLACE THE FILE LOCATION INTO A TEXTBOX THEN PASS IT TO fileloc.
Thank you a lot.