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. 从数据库插入/检索图像
- 7. 如何使用PHP在MySQL数据库中插入图像?
- 8. 如何使用spring mvc框架从mysql数据库插入和检索图像?
- 9. 检索Mysql数据库中的图像,并使用java显示
- 10. 如何使用spring从Mysql数据库中检索图像?
- 11. 检索数据并插入数据库
- 12. 插入图像到数据库并检索它
- 13. 如何在jsp中检索mysql数据库中的blob图像
- 14. 如何在主机数据库中使用VB.NET插入数据
- 15. 如何从sqlite数据库插入和检索图像?
- 16. 如何从数据库使用数据库检索图像?
- 17. 从列表视图中插入多个数据库行 - VB.NET MYSQL
- 18. 用longblob数据类型在mysql数据库中插入图像
- 19. 如何使用PHP从MYSQL插入和检索图像blob?
- 20. 如何在Android中使用json从mysql数据库中检索图像
- 21. 从MySQL数据库中检索图像并使用c在网页上显示#
- 22. 如何将图像插入数据库并在gidview中显示
- 23. 如何使用phpmyadmin在数据库中插入图像?
- 24. 如何在android sqlite数据库中插入和检索捕获图像
- 25. 通过使用vb检索数据库mysql中的图像
- 26. 使用Python从MySQL数据库中检索多个图像3
- 27. 插入和检索Postgresql数据库形式VBNet中的图像
- 28. 插入图像到MySQL数据库
- 29. 插入图像到MySQL数据库
- 30. 如何使用linq在数据库中插入一行时检索身份ID
这是stackoverflow,而不是pyschicoverflow。发布一些代码并告诉我们你正在得到哪个错误。 – 2013-02-21 19:22:28