|
|
#5
ztsjznc2017-12-19 15:02
存入数据库
Select Case Me.Text
Case "员工证件记录_新增"
If IsPicExist = True Then
Dim Data(fs.Length) As Byte
fs.Read(Data, 0, Int(fs.Length))
Dim Sql As String
Sql = "Select * from 证件记录"
Dim cmd As New SqlClient.SqlCommand(Sql, cn)
= "Insert Into 证件记录 (身份证号,姓名,证件名称,取证日期,证件照片) Values (@IDcard,@txtname,@PicName,@date,@photo)"
cmd.Connection = cn
Dim prm1 As New SqlParameter("@IDcard", str1)
Dim prm2 As New SqlParameter("@txtname", str2)
Dim prm3 As New SqlParameter("@PicName", str3)
Dim prm4 As New SqlParameter("@date", date1)
Dim prm5 As New SqlParameter("@photo", SqlDbType.VarBinary, Int(fs.Length), ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Current, Data)
cmd.Parameters.Add(prm1)
cmd.Parameters.Add(prm2)
cmd.Parameters.Add(prm3)
cmd.Parameters.Add(prm4)
cmd.Parameters.Add(prm5)
cmd.ExecuteNonQuery()
MsgBox("添加证件记录成功!")
fs.Dispose()
读出数据
Public Sub FillDialog()
Try
'打开连接
Dim sql As String
sql = "Select * From 证件记录 where ID =@ID"
Dim cmd As New SqlClient.SqlCommand(sql, cn)
Dim prm As New SqlParameter("@ID", DataGridViewId)
cmd.Parameters.Add(prm)
Dim da As New SqlClient.SqlDataAdapter(cmd) '定义sqldataadapter并于sqlcommand连接
Dim ds As New DataSet
da.Fill(ds, "证件记录")
If ds.Tables("证件记录").Rows.Count <> 0 Then
If ds.Tables("证件记录").Rows(0)("证件照片") Is DBNull.Value Then
PictureBox1.Image = Nothing
Else
Dim data() As Byte
data = ds.Tables("证件记录").Rows(0)("证件照片")
Dim stmphoto As New MemoryStream(data)
PictureBox1.Image = Image.FromStream(stmphoto)
TextBox1.Text = ds.Tables("证件记录").Rows(0)("身份证号").ToString
txtname.Text = ds.Tables("证件记录").Rows(0)("姓名").ToString
cmbPicName.Text = ds.Tables("证件记录").Rows(0)("证件名称").ToString
DateTimePicker1.Value = ds.Tables("证件记录").Rows(0)("取证日期").ToString
End If
End If
Catch err As System.Exception
MsgBox(err.Message, vbOKOnly + vbCritical, "出错信息提示")
End Try
End Sub
|