rpt_ImPort.Detail = "SELECT T_ImportHeader.ImportNo,ImportStatus,ImportDate,DocRef,ImportType," & _
"ILineNo,T_ImportDetail.ProductCode,' ' as ProductName,T_ImportDetail.Logo,T_ImportDetail.ProductType,T_ImportDetail.Brand,T_ImportDetail.Qty " & _
" FROM T_ImportHeader,T_ImportDetail " & _
" WHERE ( T_ImportHeader.ImportNo LIKE @ImportNo AND ImportStatus LIKE @ImportStatus AND DocRef LIKE @DocRef AND ImportType LIKE @ImportType AND T_ImportHeader.ImportNo=T_ImportDetail.ImportNo " & _
" AND ImportDate BETWEEN @ImportDateFrom AND @ImportDateTo )" & _
" ORDER BY T_ImportHeader.ImportNo,ILineNo ASC "
Code (VB.NET)
Private Function LoadDataHead() As DataTable
Dim com As New OleDbCommand
Dim dr As OleDbDataReader
Dim dt As DataTable
Dim _ImportNo As String = "%" & tbImportNo.Text.Trim & "%"
Dim _DocRef As String = "%" & tbDocRef.Text.Trim & "%"
Dim _status As String = "%" & cbStatus.SelectedItem & "%"
Dim _ImportDateFrom As Date = dtImportDateForm.Value
Dim _ImportDateTo As Date = dtImportDateTo.Value
Dim _IMType As String = "%" & cbIMType.SelectedItem & "%"
With com
.CommandText = rpt_ImPort.Detail
.CommandType = CommandType.Text
.Connection = Conn
.Transaction = tr
.Parameters.Clear()
.Parameters.Add("@ImportNo", OleDbType.VarChar).Value = _ImportNo
.Parameters.Add("@ImportStatus", OleDbType.VarChar).Value = _status
.Parameters.Add("@DocRef", OleDbType.VarChar).Value = _DocRef
.Parameters.Add("@ImportType", OleDbType.VarChar).Value = _IMType
.Parameters.Add("@ImportDateFrom", OleDbType.Date).Value = _ImportDateFrom
.Parameters.Add("@ImportDateTo", OleDbType.Date).Value = _ImportDateTo
dr = .ExecuteReader()
dt = New DataTable
dt.Load(dr)
If dt.Rows.Count > 0 Then ' err ว่าอ่านค่าได้อย่างเดียว ทำยังไงถึงจะเก็บค่าได้
Dim drow As DataRow
Dim i As Integer = 0
For Each drow In dt.Rows
drow("ProductName") = Me.GetCustomerName(drow("ProductCode"))
Next
End If
End With
Return dt
End Function
Private Function GetCustomerName(ByVal customerName As String) As String
Dim bs As New DataViewManager
Dim datagv As New DataGridView
Dim ds2 As New DataSet()
Dim sqlCompany As String = ""
sqlCompany = "SELECT * FROM M_Customer "
sqlCompany = sqlCompany & " WHERE (CustomerCode='" & customerName & "')"
da = New OleDbDataAdapter(sqlCompany, Conn)
ds2.Tables.Clear()
da.Fill(ds2, "Customer")
datagv.DataSource = ds2.Tables("Customer")
If ds2.Tables("Customer").Rows.Count > 0 Then
customerName = ds2.Tables("Customer").Rows(0).Item("CustomerNameTH")
End If
Return customerName
End Function