0
A
回答
0
我这里有一个C#实现,但你可以使用a c# to VB.Net converter
在aspx文件:
<asp:FileUpload runat="server" ID="fuPersonPicture" />
<asp:Button runat="server" ID="btnPhotoUpload" Text="Upload" OnClick="btnPhotoUpload_Click" />
在后台代码:
定义的protected void btnPhotoUpload_Click(object sender, EventArgs e)
{
byte[] rawData = new byte[fuPersonPicture.FileBytes.Length];
int fileSize = fuPersonPicture.FileBytes.Length;
fuPersonPicture.FileContent.Read(rawData, 0, fileSize);
string extension = Path.GetExtension(fuPersonPicture.PostedFile.FileName);
switch (extension.ToLower())
{
// Only allow uploads that look like images.
case ".jpg":
case ".jpeg":
case ".gif":
case ".png":
case ".bmp":
System.Drawing.Image myImage = System.Drawing.Image.FromStream(fuPersonPicture.PostedFile.InputStream);
fuPersonPicture.FileContent.Close();
PersonPictureManager.Insert(fuPersonPicture.FileName, fileSize, rawData, myImage.Height, myImage.Width);
//lbUploadMessage.Text = string.Empty;
break;
default:
//lbUploadMessage.Text = "<br>File is not a valid image file (JPG, JPEG, GIF, BMP, PNG).";
break;
}
fuPersonPicture.FileContent.Close();
}
PersonPictureManager.Insert()
public static void Insert(string FileName, int FileSize, byte[] RawData, int ImageHeight, int ImageWidth)
{
string strSQL = "insert into person_picture (file_id, file_name, file_size, file, width, height) values (NULL, @file_name, @file_size, ?file, @width, @height)";
using (MySqlCommand cmd = new MySqlCommand(strSQL))
{
cmd.Parameters.Add(new MySqlParameter("@file_name", FileName));
cmd.Parameters.Add(new MySqlParameter("@file_size", FileSize));
cmd.Parameters.Add(new MySqlParameter("@height", ImageHeight));
cmd.Parameters.Add(new MySqlParameter("@width", ImageWidth));
cmd.Parameters.Add(new MySqlParameter("?file", RawData));
DatabaseConnection.ExecuteNonQuery(cmd); // Just a DB helper class
}
}
+0
感谢它帮助我解决了我的问题... – Devraj 2013-03-12 18:01:44
相关问题
- 1. 如何在vb.net中从数据库检索二进制图像并在网格视图中插入图像
- 2. PDO在数据库中插入图像并检索图像
- 3. 插入并从Mysql数据库检索图像
- 4. VB.net - 从MySQL插入/检索图片数据库直接进入/从一个Picturebox
- 5. 如何从C#插入图像并从数据库中检索图像?
- 6. 检索Mysql数据库中的图像,并使用java显示
- 7. 如何使用spring从Mysql数据库中检索图像?
- 8. 检索数据并插入数据库
- 9. 如何从数据库使用数据库检索图像?
- 10. 如何使用PHP从MYSQL插入和检索图像blob?
- 11. 如何在Android中使用json从mysql数据库中检索图像
- 12. 如何使用phpmyadmin在数据库中插入图像?
- 13. 如何在android sqlite数据库中插入和检索捕获图像
- 14. 使用Python从MySQL数据库中检索多个图像3
- 15. 通过使用vb检索数据库mysql中的图像
- 16. 插入和检索Postgresql数据库形式VBNet中的图像
- 17. 插入图像到MySQL数据库
- 18. 插入图像到MySQL数据库
- 19. 如何使用linq在数据库中插入一行时检索身份ID
- 20. 如何在Golang中的MySQL数据库中存储和检索图像数据
- 21. 如何在C#中使用mysql数据库插入数据
- 22. 如何从数据库检索图像?
- 23. php-how如何在数据库中插入图像并使用php显示
- 24. 如何从数据库检索图像并放置在JSP上?
- 25. 如何使用Struts 2在Postgres数据库中插入/检索数据?
- 26. 从FCK编辑器中检索上传的图像并插入数据库
- 27. 并行进程在数据库中插入数据
- 28. 在MySQL数据库中检索非英文字符插入值
- 29. 如何通过VB.NET在sql server数据库中存储和检索图像
- 30. 如何使用PHP搜索栏检索MySQL数据库数据
这是stackoverflow,而不是pyschicoverflow。发布一些代码并告诉我们你正在得到哪个错误。 – 2013-02-21 19:22:28