Private Sub BT1_Click(sender As Object, e As EventArgs) Handles BT1.Click
If System.IO.File.Exists(Me.OpenFileDialog1.FileName) = False Then
MessageBox.Show("File Not Found", "Error")
Exit Sub
Else
Dim strConn As String = "Data Source=DATABASE\SQLEXPRESS;Initial Catalog=GPS;Persist Security Info=True;User ID=sa;Password=Password@2017"
'strConn ให้เปลี่ยนค่าตามเครื่อง Server ของ SQL Server ที่ติดต่อ
Dim Conn As New SqlConnection(strConn)
Dim SqlString As String
'### อยากเพิ่มข้อมูล TEXT เพิ่มแค่ 3 ช่องนี้ลงไป ######################
SqlString = "INSERT INTO db_IVMS(iv0,iv1,iv2,iv3,iv4,iv5,iv6,iv7,iv8,iv9) " &
" VALUES(@num,@detail, @edit,@regis,@date,@time,@gps,@name,@pic1,@pic2)"
'### อยากเพิ่มข้อมูล TEXT เพิ่มแค่ 3 ช่องนี้ลงไป #######################
Dim cmd As SqlCommand = New SqlCommand(SqlString, Conn)
Dim ImgName As SqlParameter = New SqlParameter("@num",
System.Data.SqlDbType.Int, 100)
Dim imgpic As SqlParameter = New SqlParameter("@detail",
System.Data.SqlDbType.VarChar, 10000)
Dim edit As SqlParameter = New SqlParameter("@edit",
System.Data.SqlDbType.VarChar, 10000)
Dim regis As SqlParameter = New SqlParameter("@regis",
System.Data.SqlDbType.VarChar, 100)
Dim date1 As SqlParameter = New SqlParameter("@date",
System.Data.SqlDbType.VarChar, 100)
Dim time1 As SqlParameter = New SqlParameter("@time",
System.Data.SqlDbType.VarChar, 100)
Dim gps As SqlParameter = New SqlParameter("@gps",
System.Data.SqlDbType.VarChar, 100)
Dim name As SqlParameter = New SqlParameter("@name",
System.Data.SqlDbType.VarChar, 100)
'### อยากเพิ่มข้อมูล TEXT เพิ่มแค่ 3 ช่องนี้ลงไป ########################
cmd.Parameters.Add("@num", SqlDbType.Int).Value = IV0.Text
cmd.Parameters.Add("@detail", SqlDbType.VarChar).Value = IV1.Text
cmd.Parameters.Add("@edit", SqlDbType.VarChar).Value = IV2.Text
cmd.Parameters.Add("@regis", SqlDbType.VarChar).Value = IV3.Text
cmd.Parameters.Add("@date", SqlDbType.VarChar).Value = IV4.Text
cmd.Parameters.Add("@time", SqlDbType.VarChar).Value = IV5.Text
cmd.Parameters.Add("@gps", SqlDbType.VarChar).Value = IV6.Text
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = IV7.Text
'ImgName.Value = IV0.Text.ToString()
'imgpic.Value = IV1.Text.ToString()
'edit.Value = IV2.Text.ToString()
'regis.Value = IV3.Text.ToString()
'date1.Value = IV4.Text.ToString()
'time1.Value = IV5.Text.ToString()
'gps.Value = IV6.Text.ToString()
'name.Value = IV7.Text.ToString()
'cmd.Parameters.Add(ImgName)
'cmd.Parameters.Add(imgpic)
'cmd.Parameters.Add(edit)
'cmd.Parameters.Add(regis)
'cmd.Parameters.Add(date1)
'cmd.Parameters.Add(time1)
'cmd.Parameters.Add(gps)
'cmd.Parameters.Add(name)
Dim Img As SqlParameter = New SqlParameter("@pic1",
System.Data.SqlDbType.Image)
Dim img2 As SqlParameter = New SqlParameter("@pic2",
System.Data.SqlDbType.Image)
Img.Value = fsImage
img2.Value = fsImage
cmd.Parameters.Add(Img)
cmd.Parameters.Add(img2)
Try
Conn.Open()
cmd.ExecuteNonQuery()
Conn.Close()
MessageBox.Show("Save Image Complete", "Success")
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error")
Exit Sub
End Try
End If
End Sub
Tag : .NET, Ms SQL Server 2014, Crystal Report, VB.NET