您好感谢了很多,我有以下一个代码在这段代码生病上传一张图片。 它转换成字节码,并将其存储在数据库..并在GridView控件retrive它..事情是把它转换成字节码之前,我想调整它可以üPLZ告诉我,我应该插入什么代码在这里...非常感谢......
protected void btnUpload_Click(object sender, EventArgs e)
{
string strID= txtid.Text.ToString();
string strImageName = txtName.Text.ToString();
if (FileUpload1.PostedFile != null &&
FileUpload1.PostedFile.FileName != "")
{
byte[] imageSize = new byte
[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
uploadedImage.InputStream.Read
(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
// Create SQL Connection
SqlConnection con = new SqlConnection("user id=sa;password=Zoomin@123;database=salary_db;server=192.168.1.100");
// Create SQL Command
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO image1(ID,ImageName,Image)" +
" VALUES (@ID,@ImageName,@Image)";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlParameter ID = new SqlParameter
("@ID", SqlDbType.VarChar, 50);
ID.Value = strID.ToString();
cmd.Parameters.Add(ID);
SqlParameter ImageName = new SqlParameter
("@ImageName", SqlDbType.VarChar, 50);
ImageName.Value = strImageName.ToString();
cmd.Parameters.Add(ImageName);
SqlParameter UploadedImage = new SqlParameter
("@Image", SqlDbType.Image, imageSize.Length);
UploadedImage.Value = imageSize;
cmd.Parameters.Add(UploadedImage);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
if (result > 0)
lblMessage.Text = "File Uploaded";
GridView1.DataBind();
}}