如何在Query中不添加gridview最后的组合框值 [英] How to not add gridview last combobox value in Query
本文介绍了如何在Query中不添加gridview最后的组合框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网格视图,其中包含一行包含
1.用于列选择的Combobox
2.用于搜索方法的Combobx(=,like,<, <>,>)
3.搜索文本框(搜索内容)
4.运算符组合框(AND / OR)
我使用此代码将where子句发送到Store程序
I have a grid view which include a row that contain
1. Combobox for column selection
2. Combobx for searching method (=, like, <, <>, >)
3. Text box for search (what to search)
4. Combobox for operator (AND/OR)
I am using this code to send where clause to Store procedure
private void buttonX1_Click(object sender, EventArgs e)
{
lblRecordNo.Text = "";
foreach (DataGridViewRow Datarow in dataGridView1.Rows)
{
if (dataGridView1.RowCount == 1) //When DataGridview Contain only one row
{
if (Datarow.Cells[0].Value != null && Datarow.Cells[1].Value != null && Datarow.Cells[2].Value != null)//&& Datarow.Cells[3].Value != null)
{
WhereClause += Datarow.Cells[0].Value.ToString() + " " + Datarow.Cells[1].Value.ToString() + " " + Datarow.Cells[2].Value.ToString() + " ";
SearchQuery = WhereClause;
}
else
{
MessageBox.Show("Must Fill Column-کالم لازمی پر کریں","Error",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
else if (dataGridView1.RowCount > 1) //When DataGridview Contain MOre then 1 row
{
if (Datarow.Cells[0].Value != null && Datarow.Cells[1].Value != null && Datarow.Cells[2].Value != null && Datarow.Cells[3].Value != null)
{
WhereClause += Datarow.Cells[0].Value.ToString() + " " + Datarow.Cells[1].Value.ToString() + " " + Datarow.Cells[2].Value.ToString()+ " " + Datarow.Cells[3].Value.ToString()+ " ";
SearchQuery = WhereClause;
}
else
{
MessageBox.Show("Must Fill Column-کالم لازمی پر کریں", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
//for testing search query ! What is this?
MessageBox.Show(SearchQuery);
//passing value to BLL CLass
objSearching.WhereClause = SearchQuery;
//pass Searched values to Form1 (Main Form) of Application.Bind also Search's tab Combobx and textboxes
//this work require to do!!!!!
FrmMain.dgvhadiths.DataSource = objSearching.HadithSearching();
dgvSearchHadith.DataSource = objSearching.HadithSearching();
//reset the searching query variable
lblRecordNo.Text = dgvSearchHadith.Rows.Count.ToString();
WhereClause = ""; SearchQuery = ""; BookSelection="";
}
这很好但是如果用户在Datagridview中添加多行,那么如何不添加
This fine but the poblem if user add more then one row in Datagridview then how to not add
Datarow.Cells[3].Value.ToString()
这包含和/或关键字
推荐答案
我不确定检查这个
i am not sure check this one
foreach (DataGridViewRow Datarow in dataGridView1.Rows)
{
if (dataGridView1.RowCount == Datarow.Index +1) //check if it is the last row other wise do the else
{
if (Datarow.Cells[0].Value != null && Datarow.Cells[1].Value != null && Datarow.Cells[2].Value != null)//&& Datarow.Cells[3].Value != null)
{
WhereClause += Datarow.Cells[0].Value.ToString() + " " + Datarow.Cells[1].Value.ToString() + " " + Datarow.Cells[2].Value.ToString() + " ";
SearchQuery = WhereClause;
}
else
{
MessageBox.Show("Must Fill Column-کالم لازمی پر کریں", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else// except the last row
{
if (Datarow.Cells[0].Value != null && Datarow.Cells[1].Value != null && Datarow.Cells[2].Value != null && Datarow.Cells[3].Value != null)
{
WhereClause += Datarow.Cells[0].Value.ToString() + " " + Datarow.Cells[1].Value.ToString() + " " + Datarow.Cells[2].Value.ToString() + " " + Datarow.Cells[3].Value.ToString() + " ";
}
else
{
MessageBox.Show("Must Fill Column-کالم لازمی پر کریں", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
告诉我它是否有用
tell me if it work or not
您可以查看Stephen Thomas在他的书Beginning WPF 4.5 by Full Examples中撰写的示例。它们简单明了,他们帮助了我 - http://tekkiebooks.com/Product/9db79251- 4ddb-42c5-819e-873cce0f4d5f / codeproject_02 [ ^ ]
祝你好运!
You can check out the examples written by Stephen Thomas in his book Beginning WPF 4.5 by Full Examples. They are simple, clear and they helped me - http://tekkiebooks.com/Product/9db79251-4ddb-42c5-819e-873cce0f4d5f/codeproject_02[^]
Good luck!
这篇关于如何在Query中不添加gridview最后的组合框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文