11-01-21, 02:21 AM
(آخر تعديل لهذه المشاركة : 11-01-21, 02:28 AM {2} بواسطة اليوم السابع.)
(11-01-21, 02:11 AM)1nj كتب : معناتو حنرجع للكود الاول وبدل name نضع admin وبكده يعرض الاعداد كلها
كود :
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("admin").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
For Each item In query
MsgBox(item.Key & " " & item.Value)
Next
لو فيه true و false و احمد
حيكون مثلا
true = 30
false = 12
احمد = 43
هو نجح الامر تسلم ايدكم جميعا ولكن النقطه هنا في حال استراد البيانات من ملف اكسيل و الكود في بوتن بيشوف ان الداتا تيبل فارغه
ولكن لو اضفت الكود هنا بيشتغل تمام
كود :
Dim filePath As String = OpenFileDialog1.FileName
Dim extension As String = Path.GetExtension(filePath)
Dim header As String = If(rbHeaderYes.Checked, "YES", "NO")
Dim conStr As String, sheetName As String
conStr = String.Empty
Select Case extension
Case ".xls"
'Excel 97-03
conStr = String.Format(Excel03ConString, filePath, header)
Exit Select
Case ".xlsx"
'Excel 07
conStr = String.Format(Excel07ConString, filePath, header)
Exit Select
End Select
'Get the name of the First Sheet.
Using con As New OleDbConnection(conStr)
Using cmd As New OleDbCommand()
cmd.Connection = con
con.Open()
Dim dtExcelSchema As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
sheetName = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()
con.Close()
End Using
End Using
'Read Data from the First Sheet.
Using con As New OleDbConnection(conStr)
Using cmd As New OleDbCommand()
Using oda As New OleDbDataAdapter()
Dim dt As New DataTable()
cmd.CommandText = (Convert.ToString("SELECT * From [") & sheetName) + "]"
cmd.Connection = con
con.Open()
oda.SelectCommand = cmd
oda.Fill(dt)
con.Close()
'Populate DataGridView.
GridControl1.DataSource = dt
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("privacy").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
For Each item In query
MsgBox(item.Key & " " & item.Value)
Next
End Using
End Using
End Using(11-01-21, 02:21 AM)اليوم السابع كتب :الخطأ من عندي اسف فعلا انا ضايف 2 داتا تيبل(11-01-21, 02:11 AM)1nj كتب : معناتو حنرجع للكود الاول وبدل name نضع admin وبكده يعرض الاعداد كلها
كود :
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("admin").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
For Each item In query
MsgBox(item.Key & " " & item.Value)
Next
لو فيه true و false و احمد
حيكون مثلا
true = 30
false = 12
احمد = 43
هو نجح الامر تسلم ايدكم جميعا ولكن النقطه هنا في حال استراد البيانات من ملف اكسيل و الكود في بوتن بيشوف ان الداتا تيبل فارغه
ولكن لو اضفت الكود هنا بيشتغل تمام
كود :
Dim filePath As String = OpenFileDialog1.FileName
Dim extension As String = Path.GetExtension(filePath)
Dim header As String = If(rbHeaderYes.Checked, "YES", "NO")
Dim conStr As String, sheetName As String
conStr = String.Empty
Select Case extension
Case ".xls"
'Excel 97-03
conStr = String.Format(Excel03ConString, filePath, header)
Exit Select
Case ".xlsx"
'Excel 07
conStr = String.Format(Excel07ConString, filePath, header)
Exit Select
End Select
'Get the name of the First Sheet.
Using con As New OleDbConnection(conStr)
Using cmd As New OleDbCommand()
cmd.Connection = con
con.Open()
Dim dtExcelSchema As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
sheetName = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()
con.Close()
End Using
End Using
'Read Data from the First Sheet.
Using con As New OleDbConnection(conStr)
Using cmd As New OleDbCommand()
Using oda As New OleDbDataAdapter()
Dim dt As New DataTable()
cmd.CommandText = (Convert.ToString("SELECT * From [") & sheetName) + "]"
cmd.Connection = con
con.Open()
oda.SelectCommand = cmd
oda.Fill(dt)
con.Close()
'Populate DataGridView.
GridControl1.DataSource = dt
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("privacy").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
For Each item In query
MsgBox(item.Key & " " & item.Value)
Next
End Using
End Using
End Using
بجد شكرا لكم جميعا
ويارب يكون الموضوع افاده لي اي عضو اخر محتاج مساعده في نفس النقطه
(11-01-21, 02:11 AM)1nj كتب : معناتو حنرجع للكود الاول وبدل name نضع admin وبكده يعرض الاعداد كلها
كود :
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("admin").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
For Each item In query
MsgBox(item.Key & " " & item.Value)
Next
لو فيه true و false و احمد
حيكون مثلا
true = 30
false = 12
احمد = 43
سؤال اخير بقي ومش هشغلكم تاني انا اسف عارف اني طولت والله
طيب انا لو عاوز اخذ القيم (الاعداد) و الاسم (Key) في متغير كيف مع العلم انا معرفش عددهم

