制作2个表,第一个表包含textbox1的文本[可能是“name”],textbox2的文本[可能是“surname”]和imageId[],另一个表包含文件id,文件字节和文件扩展名。当您用图片保存上述信息时。获取图像字节并扩展保存它。当您获取图像以便在某处显示时,您可以通过其扩展名将字节转换为文件 http://www.beansoftware.com/ASP.NET-Tutorials/Save-Read-Image-Database.aspx 在这里用于 ASP.NET 但是.net 中的控件通常是相同的。(textbox.Text 等)
private void Button1_Click(object sender, System.EventArgs e)
{
Stream img_strm = upload_file.PostedFile.InputStream;
//Retrieving the length of the file to upload
int img_len = upload_file.PostedFile.ContentLength;
//retrieving the type of the file to upload
string strtype = upload_file.PostedFile.ContentType.ToString();
string strname = txtimgname.Text.ToString();
byte[] imgdata = new byte[img_len];
int n = img_strm.Read(imgdata, 0, img_len);
int result = SaveToDB(strname, imgdata, strtype);}
Run Code Online (Sandbox Code Playgroud)