本文介绍了面临错误:无法将位从位图转换为字节[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void Upload_Click_1(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
//img filter
open.Filter = "ImageFiles(*.jpg; *.jpeg; *.gif; *.bmp;)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
String photoFilePath = open.FileName.ToString();
pic.ImageLocation = photoFilePath;
textbox.Text = photoFilePath;
}
}
private void Save_Click(object sender, EventArgs e)
{
try
{
byte[] imageBt = null;
FileStream fs = new FileStream(this.textbox.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
imageBt = br.ReadBytes((int)fs.Length);
String connString = ConfigurationManager.ConnectionStrings["logindb"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("storeimg", conn);
//parameters
cmd.Parameters.Add("@Photo", SqlDbType.Image).Value = pic.Image;
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = IDtex.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Added");
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex.Message);
}
}
推荐答案
这篇关于面临错误:无法将位从位图转换为字节[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!