我想知道如何在 SQL Server 表中创建图像列并使用 VB.NET 在 ASP.NET 中检索它
create table Tbl(ID int primary key,Name varchar(20),Image ....)
最佳答案
您想要使用VARBINARY(MAX)来存储这些数据。
至于代码方面,here is a good, brief answer.
来自答案:
FileStream st = new FileStream(@"C:\filename.jpg", FileMode.Open);
byte[] buffer = new byte[st.Length];
st.Read(buffer, 0, (int)st.Length);
st.Close();
SqlConnection conn = new SqlConnection("...");
SqlCommand cmd = new SqlCommand(
"UPDATE SomeTable SET image=@image WHERE ID = 1", conn);
cmd.Parameters.AddWithValue("@image", buffer);
conn.Open();
int i = cmd.ExecuteNonQuery();
conn.Close();
关于asp.net - 如何在 SQL Server 表中创建图像列并使用 VB 在 ASP.NET 中检索它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9815381/