Private dTableTest As DataTable
Private Sub SetColTableTest()
dTableTest = New DataTable
'col: TestName TestID ImgTestTyp
dTableTest.Columns.Add("TestName", Type.GetType("System.String"))
dTableTest.Columns.Add("TestID", Type.GetType("System.String"))
dTableTest.Columns.Add("ImgTestType", Type.GetType("System.Object"))
End Sub
Private Sub SetRowTableTest()
If dTableTest Is Nothing Then Call SetColTableTest()
dTableTest.Rows.Clear()
Dim strSQL As String = "SELECT TST.TestName, TST.TestID, TST.ImgType" & _
" FROM .[dbo].[Test] AS TST;"
Dim strRespond As String = SendRequest(HospitalEnum.Request.Read, strSQL).Trim
Dim arrRowText() As String
Dim arrColText() As String
im newRow As DataRow
arrRowText = strRespond.Split(New Char() {"|"c})
For Each textRow As String In arrRowText
If textRow <> "" Then
arrColText = textRow.Split(New Char() {"~"c})
If arrColText.Length <> 3 Then Continue For
hospDepID = arrColText(2).Trim
If hospDepID.IndexOf("_") > -1 Then hospDepID = hospDepID.Substring(0, hospDepID.IndexOf("_"))
hospDepID = hospDepID.Replace("HD", "").Trim
newRow = dTableTest.NewRow
'col: TestName TestID ImgTestTyp
newRow(0) = arrColText(0)
newRow(1) = arrColText(1).Trim
If arrColText(2).Trim = "TG" Then
newRow(3) = ImlTestType.Images(1)
ElseIf arrColText(2).Trim = "T" Then
newRow(3) = ImlTestType.Images(2)
Else
newRow(3) = ImlTestType.Images(0)
End If
dTableTest.Rows.Add(newRow)
End If 'textRow
Next 'textRow
End Sub
Private Sub DispTestList(ByVal dispTable As DataTable)
'dgvTest คือ DataGridView
dgvTest.AutoGenerateColumns = False
dgvTest.DataSource = dispTable
'col: TestName TestID ImgTestType
dgvTest.Columns(0).DataPropertyName = dispTable.Columns(0).ColumnName
dgvTest.Columns(1).DataPropertyName = dispTable.Columns(1).ColumnName
dgvTest.Columns(2).DataPropertyName = dispTable.Columns(2).ColumnName
End Sub
เป็น Binary data ครับ
คือเอาโค๊ดมาย้ำกันจนได้แบบเนียครับคือหาดูตามเว็บมาต้องบอกบอกเลยมาผมไม่รู้หลักการเขียนเลย
คือตอน inser ข้อมูลลงผมเขียนแบบเนียครับ
If textjob.Text.Trim = Nothing Or textqty.Text.Trim = Nothing Or ComboBox1.Text = Nothing Or textdesciption.Text.Trim = Nothing Or System.IO.File.Exists(Me.dlg.FileName) = False Then
MsgBox("กรุณาใส่ข้อูลให้ครบด้วย")
ElseIf MessageBox.Show("คุณต้องการบันทึกข้อมูลใช่หรือไม่ ?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
ds = New DataSet
'da = New SqlDataAdapter("INSERT INTO tbljob (Jobno,categoryid,description,dateimport,dateexport,Qty,Remak) VALUES ('" & Me.textjob.Text.Trim() & "','" & Me.ComboBox1.SelectedValue.ToString & "','" & Me.textdesciption.Text.Trim() & "','" & Me.dtpimport.Value.ToString("yyyy-MM-dd") & "','" & Me.dtpexport.Value.ToString("yyyy-MM-dd") & "','" & CInt(Me.textqty.Text.Trim) & "','" & Me.textremak.Text.Trim() & "')", sqlcon)
da = New SqlDataAdapter("INSERT INTO tbljob (Jobno,categoryid,description,dateimport,dateexport,Qty,Remak,Image) VALUES (@Jobno,@categoryid,@description,@dateimport,@dateexport,@Qty,@Remak,@img)", sqlcon)
Dim cmd As SqlCommand = da.SelectCommand
Dim Jobno As SqlParameter = New SqlParameter("@Jobno", System.Data.SqlDbType.VarChar, 50)
Jobno.Value = textjob.Text.Trim.ToString()
cmd.Parameters.Add(Jobno)
Dim categoryid As SqlParameter = New SqlParameter("@categoryid", System.Data.SqlDbType.VarChar, 10)
categoryid.Value = ComboBox1.SelectedValue.ToString
cmd.Parameters.Add(categoryid)
Dim description As SqlParameter = New SqlParameter("@description", System.Data.SqlDbType.VarChar, 50)
description.Value = textdesciption.Text.Trim.ToString()
cmd.Parameters.Add(description)
Dim dateimport As SqlParameter = New SqlParameter("@dateimport ", System.Data.SqlDbType.Date)
dateimport.Value = dtpimport.Value.ToString("yyyy-MM-dd")
cmd.Parameters.Add(dateimport)
Dim dateexport As SqlParameter = New SqlParameter("@dateexport", System.Data.SqlDbType.Date)
dateexport.Value = dtpexport.Value.ToString("yyyy-MM-dd")
cmd.Parameters.Add(dateexport)
Dim Qty As SqlParameter = New SqlParameter("@Qty", System.Data.SqlDbType.Int)
Qty.Value = textqty.Text.Trim.ToString()
cmd.Parameters.Add(Qty)
Dim Remak As SqlParameter = New SqlParameter("@Remak", System.Data.SqlDbType.VarChar, 50)
Remak.Value = textremak.Text.Trim.ToString()
cmd.Parameters.Add(Remak)
Dim img As SqlParameter = New SqlParameter("@img", System.Data.SqlDbType.Image)
img.Value = fsImage
cmd.Parameters.Add(img)
cmd.ExecuteNonQuery()
'da.Fill(ds, "tbljob")
MsgBox("บันทึกข้อมูลเรียบร้อยแล้ว")
Call ShowData()
Call cleardata()
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error")
End Try