wpf使用列名检查datagrid单元格值

时间:2018-12-22 16:29:43

标签: wpf vb.net datagrid

无法在wpf中使用vb.net代码通过使用列名检查Datagrid单元格值并在此之后设置其值,如果我使用列索引,则将很困难,因为我有很多列和很多事务

vb.net代码:

If MetroGrid1.Rows(Z).Cells("iface_type").Value = "Morning_From" And (MetroGrid1.Rows(Z).Cells("time_val").Value <> New TimeSpan(0, 0, 0, 0)) Then
                    Dim From_OK As TimeSpan = New TimeSpan(0, 1, 30, 0)
                    Dim To_OK As TimeSpan = New TimeSpan(0, 1, 0, 0)
                    Try

                        Dim con4 As New SqlConnection
                        Dim cmd4 As New SqlCommand
                        Dim rd4 As SqlDataReader
                        Dim ds4 As New DataSet
                        'Dim CustomerIDfromtheTbl
                        con4.ConnectionString = "User Id='" & Main_frm.Uid_lbl.Text & "';Pwd='" & Main_frm.Data_pass_lbl.Text & "';DATA SOURCE='" & Main_frm.Server_lbl.Text & "';Initial Catalog='" & Main_frm.Database_lbl.Text & "';MultipleActiveResultSets=true"
                        con4.Open()
                        ds4.Clear()
                        cmd4.Connection = con4

                        cmd4.Parameters.Add("@Date1", SqlDbType.Time).Value = MetroGrid1.Rows(Z).Cells("time_val").Value - From_OK
                        cmd4.Parameters.Add("@Date2", SqlDbType.Time).Value = MetroGrid1.Rows(Z).Cells("time_val").Value + To_OK

                        'SELECT TOP 1 WITH TIES * FROM International ORDER BY News_ID DESC
                        cmd4.CommandText = "select  id,User_Name,Verify_Time,Verify_Type from att_download  where Emp_Code ='" & MetroGrid1.Rows(Z).Cells("emp_code").Value & "' and Verify_Date = '" & Format(MetroGrid1.Rows(Z).Cells("date_col").Value, ("yyyy-MM-dd")) & "' and Verify_Time >= @Date1 AND Verify_Time <= @Date2"
                        rd4 = cmd4.ExecuteReader
                        'SELECT ID FROM INVOICE_HEAD ORDER BY ID DESC LIMIT 1
                        If rd4.HasRows Then

                            rd4.Read()
                            ' MessageBox.Show(rd4.Item("Verify_Time").ToString)
                            MetroGrid1.Rows(Z).Cells("Bassma").Value = rd4.Item("Verify_Time")
                            ' MetroGrid1.Rows(Z).Cells("Att_ID1").Value = rd4.Item("id")
                            rd4.Close()
                        Else

                            'MetroGrid1.Rows(Z).Cells("Att_ID1").Value = rd4.Item("id")
                            MetroGrid1.Rows(Z).Cells("Bassma").Value = New TimeSpan(0, 0, 0, 0)


                        End If
                        con4.Close()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
EndIf

这是我的WPF代码,无法设置并返回错误('iface_type'):

can you solve my problem and check my code 


 If dr("iface_type") = "Morning_From" Then 'And (dr("time_val") <> TimeSpan.Parse("00:00:00")) Then
                    Dim From_OK As TimeSpan = TimeSpan.Parse("01:30:00")
                    Dim To_OK As TimeSpan = TimeSpan.Parse("01:00:00")
                    Try

                        Dim con4 As New SqlConnection
                        Dim cmd4 As New SqlCommand
                        Dim rd4 As SqlDataReader
                        Dim ds4 As New DataSet
                        'Dim CustomerIDfromtheTbl
                        con4.ConnectionString = "User Id='" + sb2.UserID + "';Pwd='" + sb2.Password + "';DATA SOURCE='" + sb2.DataSource + "';Initial Catalog='" + sb2.InitialCatalog + "';MultipleActiveResultSets=true"
                        con4.Open()
                        ds4.Clear()
                        cmd4.Connection = con4

                        cmd4.Parameters.Add("@Date1", SqlDbType.Time).Value = dr("time_val") - From_OK
                        cmd4.Parameters.Add("@Date2", SqlDbType.Time).Value = dr("time_val") + To_OK

                        'SELECT TOP 1 WITH TIES * FROM International ORDER BY News_ID DESC
                        cmd4.CommandText = "select  id,User_Name,Verify_Time,Verify_Type from att_download  where Emp_Code ='" & dr("emp_code") & "' and Verify_Date = '" & dr("date_col") & "' and Verify_Time >= @Date1 AND Verify_Time <= @Date2"
                        rd4 = cmd4.ExecuteReader
                        'SELECT ID FROM INVOICE_HEAD ORDER BY ID DESC LIMIT 1
                        If rd4.HasRows Then

                            rd4.Read()
                            ' MessageBox.Show(rd4.Item("Verify_Time").ToString)
                            dr("Bassma_Col") = rd4.Item("Verify_Time")
                            ' Att_Log_Grid.items(Z).Att_ID1  = rd4.Item("id")
                            rd4.Close()
                        Else

                            'Att_Log_Grid.items(Z).Att_ID1  = rd4.Item("id")
                            dr("Bassma_Col") = TimeSpan.Parse("00:00:00")


                        End If
                        con4.Close()
                    Catch ex As Exception
                          MessageBox.Show(ex.Message)
                    End Try
    EndIf


  i made alot of search and cannot reach solution that work and give result like vb.net 

0 个答案:

没有答案