[英]Search Button in C#
我知道这个问题已经被问过很多有关如何创建搜索按钮的问题。 我是C#编程的新手,我很难创建搜索,只是从其他帖子中找不到我想要的东西。 所以我希望有人能帮助我。
我已经创建了Windows窗体应用程序,并且使用了DataSet中的“ Details”视图来进行窗体设置,并且当我从记录滚动到记录时,数据正确显示在应用程序中。 我的数据存储在一个sdf文件中。 我想让人们输入“帐号”或“姓氏”,然后点击搜索按钮。 在搜索按钮之后,预定字段将随信息更新。 为了能够选择“姓氏”或“帐号”,我可以根据需要在组合框中列出项目。
我提供了一份代码副本,其中某些项目的命名已更改,以免泄露我的专业知识。 任何帮助是极大的赞赏。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void custtableBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.custtableBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.custDataSet);
}
private void label1_Click(object sender, EventArgs e)
{
}
private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
private void custtableBindingNavigatorSaveItem_Click_1(object sender, EventArgs e)
{
this.Validate();
this.custtableBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.custDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'custDataSet.custtable' table. You can move, or remove it, as needed.
this.custtableTableAdapter.Fill(this.custDataSet.custtable);
}
private void file_Name_12TextBox_TextChanged(object sender, EventArgs e)
{
}
private void fillByToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.custtableTableAdapter.FillBy(this.custDataSet.custtable);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void btnfind_Click(object sender, EventArgs e)
{
}
}
}
什么是custtableBindingNavigatorSaveItem_Click和custtableBindingNavigatorSaveItem_Click_1? 它们是相同的,如果它们是两个按钮执行相同的操作,则可以从两个按钮使用相同的方法(尽管为什么两个按钮执行相同的操作我也不知道)。
无论如何,您有一些选择,它取决于数据大小,所需的速度,数据是脱机还是数据库锁定等等。
设置查询/存储过程(过程更安全)以限制结果。 这使DB可以完成所有艰苦的工作-这正是DB所专为的。
将所有内容读入内存(表填充)并选择表-不要与Linq查询真正不同。 这意味着所有数据都处于脱机状态,您将需要确定何时以及如何将其写回到数据库(如果有的话)。
PS:我很感兴趣,您的笔名不足以掩饰您的职业是什么? 想象力疯了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.