将图像上传到SQL Server问题 [英] Upload Images into SQL Server Problem

查看:70
本文介绍了将图像上传到SQL Server问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像上传到SQL Server但我在SQL Server中看不到它。它一直都是空的。没错,我可以在屏幕上看到标签文字,但我找不到图像。



  int  imgLen = FileUpload1.PostedFile.ContentLength; 


byte [] imageBytes = new 字节 [imgLen];
FileUpload1.PostedFile.InputStream.Read(imageBytes, 0 ,imgLen);


string connStr = ConfigurationManager.ConnectionStrings [ ApplicationServices]的ConnectionString。
SqlConnection con = new SqlConnection(connStr);
con.Open();
SqlCommand komut = new SqlCommand( INSERT INTO resim_listesi(resim)VALUES(@img_data),con);


komut.Parameters.AddWithValue( @ img_data ,imageBytes);


Label1.Text = 成功!;

con.Close();





问题出在哪里?为什么表resim_listesi总是空?

解决方案

添加以下行:

。 .. 
komut.Parameters.AddWithValue( @ img_data,imageBytes);
komut.ExecuteNonQuery(); // 添加此行以运行插入命令


I am uploading images into SQL Server but i can''t see it in SQL Server. It''s null all the time. No error, i can see label text on the screen but i can''t find images.

    int imgLen = FileUpload1.PostedFile.ContentLength;


     byte[] imageBytes = new byte[imgLen];
     FileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imgLen);


     string connStr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
     SqlConnection con = new SqlConnection(connStr);
     con.Open();
     SqlCommand komut = new SqlCommand("INSERT INTO resim_listesi (resim) VALUES (@img_data)", con);


     komut.Parameters.AddWithValue("@img_data", imageBytes);


     Label1.Text = "successful !";

con.Close();



Where is the problem ? Why the table , "resim_listesi" is allways null ?

解决方案

Add the following line :

...
komut.Parameters.AddWithValue("@img_data", imageBytes);
komut.ExecuteNonQuery();// add this line to run the insert command


这篇关于将图像上传到SQL Server问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆