现有在sql server中有表student,字段为studentid(int),Name(varchar), photo(image),请问如何在表中保存和提取图片等。老师要求保存和提取该数据表中的信息(包括图片)全部用存储过程来实现,在WINFORM下开发,C/S形式,高手帮们给段代码吧!小弟初学C#,给段详细代码过程小弟拜谢了!!!!
解决方案 »
- VSTO.Outlook 如何把窗体区域中的显示的自定义字段发送给对方
- 如何实现类似于VS里面的属性窗口
- datagridview 行选择改变是哪个事件?
- 程序打包成setup的,怎么办
- 密码错误问题!!!!1
- C++中的 CDialog类到C#里面是哪个类啊?
- 请教: 这个错误提示什么意思.
- 关于用户控件的问题,急!
- C# socket 异步服务端丢失数据
- 未能加载文件或程序集“MyDbAdapters”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
- 我是新手,请各位帮忙
- 高分了,axWebBrowser的拖拽超链接的事件到底如何实现啊???
Exit Sub
End If
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
With PictureBox1
.Image = Image.FromFile(OpenFileDialog1.FileName)
.SizeMode = PictureBoxSizeMode.CenterImage
.BorderStyle = BorderStyle.Fixed3D
End With
End IfDim ms As New MemoryStream()
PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
Dim arrImage() As Byte = ms.GetBuffer
ms.Close()
Dim imgid As String = CInt(Int(10 * Rnd()) + Int(100 * Rnd()) + Int(1000 * Rnd()) + Int(10000 * Rnd()) + Int(100000 * Rnd()) + Int(1000000 * Rnd()) + Int(10000000 * Rnd())).ToString
Try
Dim conn As New GWConnection()
Dim northwindConnection As New SqlConnection()
northwindConnection = conn.GetCN()Dim strSQL As String = "INSERT INTO t2_005(imgid,pactcode,Picture) VALUES(@imgid,@pactcode,@Picture)"
Dim cmd As New SqlCommand(strSQL, northwindConnection)
With cmd
.Parameters.Add(New SqlParameter("@imgid", SqlDbType.NVarChar, 50)).Value = imgid
.Parameters.Add(New SqlParameter("@pactcode", SqlDbType.NVarChar, 16)).Value = txt_pactcode.Text
.Parameters.Add(New SqlParameter("@Picture", SqlDbType.Image)).Value = arrImage
End With
If Not northwindConnection.State = ConnectionState.Open Then
northwindConnection.Open()
End If
cmd.ExecuteNonQuery()
northwindConnection.Close()
'txt_imgid.Text = imgid
Catch ex As SqlException
MsgBox("图片上传失败!", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "出错提示!")
End Try
{
// Create a byte[] from the input file
int len = Upload.PostedFile.ContentLength;
byte[] pic = new byte[len];
Upload.PostedFile.InputStream.Read (pic, 0, len);
// Insert the image and comment into the database
SqlConnection connection = new
SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india");
try
{
connection.Open ();
SqlCommand cmd = new SqlCommand ("insert into Image "
+ "(Picture, Comment) values (@pic, @text)", connection);
cmd.Parameters.Add ("@pic", pic);
cmd.Parameters.Add ("@text", Comment.Text);
cmd.ExecuteNonQuery ();
}
finally
{
connection.Close ();
}
}private void GetImage(string str)
{
int num=this.dataGrid1.CurrentRowIndex;
if(num==-1)
{
return;
}
if(dataset.Tables[0].Rows[num]["照片"]!=Convert.DBNull)
{
byte[] bytes=(byte[])dataset.Tables[0].Rows[num]["照片"];
MemoryStream memStream=new MemoryStream(bytes);
Bitmap bitmap = new Bitmap(memStream);
memStream.Close();
this.pictureBox1.Image = bitmap;
}
else
{
this.pictureBox1.Image = null;
}
}