ÎÒÃÇͨ³£Õâôд
using (SqlDataReader drm = sqlComm.ExecuteReader())
{
drm.Read();//ÒÔϰÑÊý¾Ý¿âÖжÁ³öµÄImageÁ÷ÔÚͼƬ¿òÖÐÏÔʾ³öÀ´.
MemoryStream ms = new MemoryStream((byte[])drm["Logo"]);
Image img = Image.FromStream(ms);
this.pictureBox1.Image = img;
}
ÎÒµÄдÊý¾Ý
private void btnOK_Click(object sender, EventArgs e)
{
string name = "";
if (tbxUserName.Text.Trim() == "")
{
MessageBox.Show("ÐÕÃû²»ÄÜΪ¿Õ£¬ÇëÖØÐÂÊäÈ룡", "Ìáʾ");
return;
}
else
{
name = tbxUserName.Text.Trim();
}
string group = "";
if (cbxGroup.Text.Trim() == "")
{
group = "δ·Ö×é";
}
else
{
group = cbxGroup.Text.Trim();
}
string phone = tbxTel.Text.Trim();
string workunit = tbxWorkUnit.Text.Trim();
string email = tbxEmail.Text.Trim();
string qq = tbxQQ.Text.Trim();
byte[] b = null;
if (txtFilePath != "")
{
try
{
FileStream fs = new FileStream(txtFilePath, FileMode.Open, FileAccess.Read);//ÀàÐÍΪ´ò¿ªÊý¾Ý ȨÏÞΪֻ¶Á ²»ÄØÐ´Êý¾Ý
int length = Convert.ToInt32(fs.Length);
b = new byte[length];
fs.Read(b, 0, length);//Êý¾Ý¶ÁÈëbÊý×éÖÐ ´Ó0ºÅµ½lengthλ
fs.Close();//¹Ø±ÕÊäÈëÊä³öÁ÷
}
catch (Exception ex)
{
b = null;
MessageBox.Show(ex.Message);
}
}
else
{
b = pixData;
}
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
//»ñÈ¡µ±Ç°µÄÊý¾ÝÔÚ±íÖеÄID
SqlCommand commandInsert = new SqlCommand();
commandInsert.Connection = connection;
//connection.Close();
connection.Open();
//²åÈëÊý¾Ý
commandInsert.CommandText = "USE db_TXL UPDATE tb_BusicInfo set Groups= @Groups ,Name=@Name,WorkUnit=@WorkUnit,Phone=@Phone,Email=@Email,QQ=@QQ,Picture=@Picture";
commandInsert.CommandText += " where ID=@ID ";
commandInsert.Parameters.Add("@ID", SqlDbType.Int);
commandInsert.Parameters.Add("@Groups", SqlDbType.VarChar, 50);
commandInsert.Parameters.Add("@Name", SqlDbType.VarChar, 20);
commandInsert.Parameters.Add("@WorkUnit", SqlDbType.VarChar, 50);
commandInsert.Parameters.Add("@Phone", SqlDbType.VarChar, 14);
commandInsert.Parameters.Add("@Email", SqlDbType.VarChar, 50);
commandInsert.Parameters.Add("@QQ", SqlDbType.VarChar, 20);
commandInsert.Parameters.Add("@Picture", SqlDbType.Image);//ImageµÄÀàÐͲ»ÄÜд´í£¡£¡
commandInsert.Parameters["@ID"].Value = ID;
// commandInsert.Parameters["@UserName"].Value = strUserName;
commandInsert.Parameters["@Groups"].Value = group;
commandInsert.Parameters["@Name"].Value = name;
commandInsert.Parameters["@WorkUnit"].Value = workunit;
commandInsert.Parameters["@Phone"].Value = phone;
commandInsert.Parameters["@Email"].Value = email;
commandInsert.Parameters["@QQ"].Value = qq;
//commandInsert.Parameters[""].Value=;
if (txtFilePath == "" && pixData==null)
{
commandInsert.Parameters["@Picture"].Value = DBNull.Value;//DBNull ²»´æÔÚµÄÖµNULL
}
else
{
commandInsert.Parameters["@Picture"].Value = b;
}
commandInsert.ExecuteNonQuery();
connection.Close();
DialogResult = DialogResult.OK;
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
ÎҵĶÁÊý¾Ý
private void frmEdit_Load(object sender, EventArgs e)
{
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
string commandString = "select * from tb_BusicInfo where ID= " + ID.ToString() + " ";
SqlCommand command = new SqlCommand(commandString, connection);
conne