Tôi đang tạo một chương trình với máy chủ C# và sql và tôi gặp sự cố, tôi hy vọng nếu có ai giúp tôi.tài liệu mở từ (được lưu dưới dạng nhị phân) từ cơ sở dữ liệu
Tôi sẽ nhưng cơ sở dữ liệu trên máy tính và chương trình sẽ được cài đặt trong các máy tính khác và chương trình ứng dụng được kết nối với cơ sở dữ liệu đó.
các tài liệu tiết kiệm chương trình (word -excel) như nhị phân, sử dụng mã này:
byte[] ReadFile(string sPath)
{
//Initialize byte array with a null value initially.
byte[] data = null;
//Use FileInfo object to get file size.
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
//Open FileStream to read file
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
//Use BinaryReader to read file stream into byte array.
BinaryReader br = new BinaryReader(fStream);
//When you use BinaryReader, you need to supply number of bytes to read from file.
//In this case we want to read entire file. So supplying total number of bytes.
data = br.ReadBytes((int)numBytes);
return data;
}
private void button1_Click(object sender, EventArgs e)
{
string dt = dateTimePicker1.Value.ToShortDateString();
byte[] red = ReadFile(textBox3.Text);
con.Open();
string qry = "insert into documents ([Account no],Name,[Phone number],Date,[Document name],Document,Type) values(@accon,@name,@phone,@date,@docname,@doc,@type)";
//Initialize SqlCommand object for insert.
SqlCommand SqlCom = new SqlCommand(qry, con);
//We are passing Original Image Path and Image byte data as sql parameters.
SqlCom.Parameters.Add(new SqlParameter("@accon", textBox1.Text));
SqlCom.Parameters.Add(new SqlParameter("@name", textBox2.Text));
SqlCom.Parameters.Add(new SqlParameter("@phone", textBox3.Text));
SqlCom.Parameters.Add(new SqlParameter("@date", dt));
SqlCom.Parameters.Add(new SqlParameter("@docname", textBox1.Text));
SqlCom.Parameters.Add(new SqlParameter("@doc", (object)red));
SqlCom.Parameters.Add(new SqlParameter("@type", (object)textBox2.Text));
SqlCom.ExecuteNonQuery();
con.Close();
MessageBox.Show("done");
}
vấn đề: mà tôi không biết làm thế nào để lấy tài liệu được lưu trong cơ sở dữ liệu và mở nó với Microsoft từ hoặc Microsoft Excel theo loại của họ.
Tôi muốn chọn cơ sở dữ liệu dạng văn bản cụ thể và mở nó
Cảm ơn trước
Bạn lưu trữ gì trong 'Loại' cho Word và điều gì cho Excel? –