private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(openFileDialog1.FileName); byte[] data = new byte[fi.Length]; DateTime dt = fi.CreationTime; FileStream fs = fi.Open(FileMode.Open, FileAccess.Read, FileShare.Read); fs.Position = 0; fs.Read(data, 0, Convert.ToInt32(fi.Length)); SqlConnection conn = new SqlConnection(string.Format("Data Source=SELVA-T;Initial Catalog=textile;Integrated Security=True" , ServerName , DatabaseName) ); try { conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO bill([Bill Name],[Date & Time],[Data]) " + string.Format("values( '{0}','{1}',@Data )" , fi.Name , dt.ToString() ) , conn); SqlParameter pdata = new SqlParameter("@Data", SqlDbType.Image); pdata.Direction = ParameterDirection.Input; pdata.SqlValue = data; cmd.Parameters.Add(pdata); cmd.ExecuteNonQuery(); long si; si = fi.Length / 1024; MessageBox.Show("u inserted the file size of " + si.ToString() + "kb"); textileDataSet3.Tables[0].Rows.Add(fi.Name, dt, data); //getting error in this underline textileDataSet3.Tables[0].AcceptChanges(); conn.Close(); } catch (Exception a) { MessageBox.Show(a.Message); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)