필터는 myTicketsSubmitButton에는 작동하지만 allTicketsSubmitButton에는 사용할 수 없습니다. 코드는 동일하지만 한 방법에서 작동하는 이유와 다른 방법에서 작동하는 이유를 이해할 수 없습니다. 난 비주얼 스튜디오 2010BindingSource filters not working
private void myTicketsSubmitButton_Click(object sender, EventArgs e)
{
String sqlQuery = "SELECT u.CallerName, t.* FROM users u INNER JOIN tickets t ON u.id = t.user WHERE u.CallerName = '" + Environment.UserName.ToLower() + "'";
GetData(sqlQuery);
if (myTicketsAllRadioButton.Checked)
{
//GetData(sqlQuery);
ticketsBindingSource.Filter = "ProblemStatus LIKE '%'";
}
if (myTicketsClosedRadioButton.Checked)
{
//GetData(sqlQuery);
ticketsBindingSource.Filter = "ProblemStatus = 'Closed'";
}
if (myTicketsOpenRadioButton.Checked)
{
//GetData(sqlQuery);
ticketsBindingSource.Filter = "ProblemStatus = 'Open'";
}
}
private void allTicketsSubmitButton_Click(object sender, EventArgs e)
{
String sqlQuery = "SELECT u.CallerName, t.* FROM users u INNER JOIN tickets t ON u.id = t.user";
GetData(sqlQuery);
if (myTicketsAllRadioButton.Checked)
{
//GetData(sqlQuery);
ticketsBindingSource.Filter = "ProblemStatus LIKE '%'";
}
if (myTicketsClosedRadioButton.Checked)
{
//GetData(sqlQuery);
ticketsBindingSource.Filter = "ProblemStatus = 'Closed'";
}
if (myTicketsOpenRadioButton.Checked)
{
//GetData(sqlQuery);
ticketsBindingSource.Filter = "ProblemStatus = 'Open'";
}
}
private void GetData(string selectCommand)
{
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
BindingSource bindingSource1 = new BindingSource();
try
{
// Specify a connection string. Replace the given value with a
// valid connection string for a Northwind SQL Server sample
// database accessible to your system.
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\testdb.accdb";
// Create a new data adapter based on the specified query.
dataAdapter = new OleDbDataAdapter(selectCommand, connectionString);
// Create a command builder to generate SQL update, insert, and
// delete commands based on selectCommand. These are used to
// update the database.
OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter);
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
ticketsBindingSource = bindingSource1;
// Resize the DataGridView columns to fit the newly loaded content.
//ticketsDataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
ticketsDataGridView.DataSource = bindingSource1;
}
catch(OleDbException)
{
MessageBox.Show("To run this example, replace the value of the connectionString variable with a connection string that is valid for your system.");
}
}
으로 윈폼과 C#을 사용하고
나는 6 개 라디오 버튼이 있습니다. allTickets 그들의
3 myTickets --open --Closed 그들의 --all
3되어 있습니다 --open --Closed --all
I myTickets 그룹의 라디오 버튼을 클릭하십시오. 모든 것이 작동합니다.
코드에 약간의 변경을했는데 allTicketsSubmitButton은 모든 티켓을 열거 나 모든 티켓을 표시하지 않습니다.
데이터베이스가 비교적 작기 때문에 제가 가면 신속하게 테스트 할 수 있습니다.
내가 5 개 항목 2 열기 이 다른 사용자에게 할당 된 진행이 항목에서 1 일을 휴일이 (그래서 그들 중 3 myTickets 있습니다).
내가 뭔가 이상한 눈치결과 표시 제대로 만 내가 같은 일에 myTickets 및 allTickets의 라디오 버튼을 설정하면
(모두 오픈 티켓을 표시합니다 개방) 하나가 열려 경우 다른 하나는 닫히고 아무 일도 일어나지 않습니다.
무엇을 작동하지
난 당신이에서 코드를 변경할 필요가 있다고 생각? 오류가 있습니까? 데이터가 그리드를 채우고 있습니까? – Taryn