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]; 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],[Data],Date1) VALUES (@File,@Data, @Date)", conn); cmd.Parameters.AddWithValue("@File", fi.Name); cmd.Parameters.AddWithValue("@Data",data); cmd.Parameters.AddWithValue("@Date", DateTime.Now); cmd.ExecuteNonQuery(); long si; si = fi.Length / 1024; MessageBox.Show("u inserted the file size of " + si.ToString() + "kb"); textileDataSet.Tables[0].Rows.Add(fi.Name,data); textileDataSet.Tables[0].AcceptChanges(); conn.Close(); } catch (Exception r) { MessageBox.Show(r.Message); } } }
AllowDBNull
false
fi.Name
data
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)