问题描述
我有一个datagridview,我通过访问数据库中的文本框过滤学生的成绩。
当我输入A或B或C或F等级时,它的工作原理如下... .it显示具有该特定年级的学生。
我想要的是显示DataGridView按钮列中每个学生的成绩总数或其他一些显示方法。
谢谢!!!
这是加载事件和我已经完成的文本框文本更改事件。
i have a datagridview that i filter the grades of students via a text box from access database.
It works like this when i type some grade like A or B or C Or F....it displays the students with that specific grade.
What i want is to display the total number of grade of each students inside a DataGridView Button Column or some other displaying method.
Thank you!!!
Here is the load event and the text box text change event that i have deone.
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports System.Data.DataTable
Public Class Form2
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Dim ds As DataSet = New DataSet
Dim da As OleDbDataAdapter
Dim tables As DataTableCollection = ds.Tables
Dim source1 As New BindingSource()
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
' dataFile = "|DataDirectory|\LMS_DB.accdb"
dataFile = "C:\Studentsgrade.accdb" ' change to access database location on your computer
connString = provider & dataFile
myConnection.ConnectionString = connString
da = New OleDbDataAdapter("Select [Student Name], [ID No], [Group], [C1], [C2], [C3], [C4], [C5], [C6], [C7], [C8], [C9], [C10], [C11], [C12], [C14], [C15], [C3], [C1], [C2], [C3], [C1], [C2], [C3], [C1], [C2], [C3], [C1], [C2], [C3] from Studentsgrade", myConnection)
da.Fill(ds, "Studentsgrade")
' replace "items" with the name of the table
' replace [Item Code], [Description], [Price] with the columns headers
Dim view1 As New DataView(tables(0))
source1.DataSource = view1
DataGridView1.DataSource = view1
DataGridView1.Refresh()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
source1.Filter = String.Format("[Student Name] LIKE '%{0}%' OR [ID No] LIKE '%{0}%' OR [Group] LIKE '%{0}%' OR [C1] LIKE '%{0}%' OR [C2] LIKE '%{0}%'", TextBox1.Text)
DataGridView1.Refresh()
End Sub
我尝试过:
i已尝试加载事件和文本框文本更改事件的代码。
What I have tried:
i have tried the code for the load event and the text box text change event.
推荐答案
- 通过过滤数据库
您需要创建 []:
- via filter database
You need to create OleDbCommand[^] with query:
SELECT <<list_of_columns>>
FROM Studentsgrade
WHERE [Student Name] LIKE @name OR [ID No] LIKE @id OR [Group] LIKE @grp OR [C1] LIKE @c1 OR [C2] LIKE @c2
并将您在 where
子句中定义的参数数量传递给 []集合。
能够 []你必须使用 [ ]通过 []。br $>
对于MS Access数据库,一些程序员更喜欢 []有些人喜欢使用 []。
and pass the number of arguments you define in where
clause to OleDbCommand.Parameters[^] collection.
To be able to load data to DataTable[^] you have to use OleDbReader[^] through the OleDbCommand.ExecuteReader() method[^].
For MS Access database some programmers prefer to filter datatable by using its method[^] and some prefer to use Linq to dataset[^].
详情请参阅:
[]
[]
[]
[]
[]
For further details, please read:
OleDbParameterCollection.AddWithValue Method (String, Object) (System.Data.OleDb)[^]
Introduction to LINQ in Visual Basic[^]
LINQ to DataSet Examples[^]
Creating a DataTable From a Query (LINQ to DataSet)[^]
Queries in LINQ to DataSet[^]
这篇关于如何在VB.NET中的datagridview中显示特定单元格的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!