listbox链接到文本框

listbox链接到文本框

本文介绍了如何将datagridview,listbox链接到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是缺乏经验的程序员,使用c#在sql中处理数据库。在我的表单中,我创建了一个搜索字段,根据combobox1和textbox1中的文本进行搜索。我的问题是我搜索的任何内容,结果都没有链接到我的文本框。它只链接datagridview和listbox,但不链接文本框。在搜索datagridview和listbox链接之前我的文本框但是在任何时候搜索它都没有。

这是我的搜索代码:

private void search()

{

string str =(@Data Source = BROTHER-PC; Initial Catalog = iEMYS; Integrated Security = True);





SqlConnection con = new SqlConnection(str);

if(comboBox1.SelectedIndex == 0)

{

尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(select * from老师,其中TeacherId喜欢'%'+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherData GridView.DataSource = ds.Tables [teacher];

listBox1.DataSource = ds.Tables [teacher];

if(teacherDataGridView.RowCount == 1 )

{



MessageBox.Show(未找到教师ID。试试另一个!);





}

}

catch(例外)

{



}

}



else if(comboBox1.SelectedIndex == 1)

{



试试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(

select * from teacher,EMYSNO喜欢'%'+ searchtext + %',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.T ables [老师];

如果(teacherDataGridView.RowCount == 1)

{



MessageBox 。显示(没有找到EMYSNO。试试另一个!);





}

}

catch(例外情况除外)

{

}

}

else if(comboBox1.SelectedIndex == 2)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(

select * from teacher其中[First Name]喜欢'%'+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, 老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师 ];

if(teacherDataGridView.RowCount == 1)

{



MessageBox.Show(First名称未找到。试试另一个!);





}

}

catch(例外ex)

{

}

}

else if(comboBox1.SelectedIndex == 3)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(select * from teacher where [Last Name] like'%+ searchtext +%',

con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, 老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [teacher];

if(teacherDataGridView.RowCount == 1)

{



MessageBox.Show(姓氏是未找到。试试另一个!);





}

}

catch(例外情况ex)

{

}

}

else if(comboBox1.SelectedIndex == 4)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(select * from teacher where sex like'%+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter(cmd) ;



DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(老师) DataGridView.RowCount == 1)

{



MessageBox.Show(找不到SexType。试试另一个!);





}

}

catch(例外情况除外)

{

}



}

else if(comboBox1 .SelectedIndex == 5)

{



试试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(select * from teacher where Hometown like'%+ searchtext +%',

con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da .Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [t eacher];

if(teacherDataGridView.RowCount == 1)

{



MessageBox.Show( 找不到故乡。试试另一个!);





}

}

catch(例外情况ex)

{

}

}

else if(comboBox1.SelectedIndex == 6)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(select * from teacher where region like'%+ searchtext +%',

con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,teacher );

teacherDataGridView.DataSource = ds.Tables [teacher];

listBox1.DataSource = ds.Tables [teacher];

if(teacherDataGridView.RowCount == 1)

{



MessageBox.Show(找不到地区。试试另一个!);





}

}

catch(例外情况除外)

{

}

}

else if(comboBox1.SelectedIndex == 7)

{



试试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(select * from teacher where Single like'%+ searchtext +%'order by TeacherId, con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSour ce = ds.Tables [老师];

如果(teacherDataGridView.RowCount == 1)

{







}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 8)

{



试试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(选择*来自老师,其中已婚,如'%'+ searchtext +%'由TeacherId订购,

con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{







}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 9)

{



试试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(

select * from teacher,其中[配偶姓名]喜欢'%'+ searchtext +%'由TeacherId订购, con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [ 老师];

if(teacherDataGridView.RowCount == 1)

{



MessageBox.Show (未找到配偶姓名!再试一次);



}

}

catch(Exception ex)

$

}

else if(comboBox1.SelectedIndex == 10)

{



试试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(选择*来自老师,其中学生喜欢'%'+ searchtext +%'由TeacherId订购,

con );

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 11)

{



try

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

选择*来自老师的机构,如'%'+ searchtext +%'由TeacherId订购,con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

MessageBox.Show(找不到机构!再试一次);

}

}

catch(Exception ex)

{

}

}

else if(comboBox1.SelectedIndex == 12)

{



尝试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(选择*来自老师,其中像'%'使用+ searchtext +%由TeacherId订购,

con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

li stBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 13)

{



试试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

选择*来自老师,其中职业喜欢'%'+ searchtext +%'由TeacherId订购,con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill( ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{



MessageBox.Show(未发现职业!再试一次);



}

}

catch(Exception ex)

$

}

else if(comboBox1.SelectedIndex == 14)

{



试试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

新SqlCommand(

选择*来自教师,其中失业者喜欢'%'+ searchtext +%'由TeacherId订购,con );

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{







}

}

catch(例外情况)

$

}

else if(comboBox1.SelectedIndex == 15)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(select * from teacher where [Telephone#1] like'%'+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter (cmd);



DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if (teacherDataGridView.RowCount == 1)

{

MessageBox.Show(找不到电话#1。试试另一个!);

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 16)

{



尝试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(

select * from teacher,其中[Telephone#2]喜欢'%'+ searchtext +%'由TeacherId订购,con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da。填写(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

MessageBox.Show (找不到电话#2。试试另一个!);

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 17)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(select * from老师的电子邮件如'%'+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherDataGridView.DataSource = ds.Tables [teacher];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

MessageBox.Show(未找到电子邮件。试试另一个!);

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 18)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(select * from teacher where [Postal Address] like'%+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

MessageBox.Show(找不到邮政地址。试试另一个!);

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 19)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(select * from teacher where [Home Address] like'%'+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

MessageBox.Show(找不到家庭住址。试试另一个!);

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 20)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd = new SqlCommand(

select * from teacher,其中[Home Area]喜欢'%'+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{



MessageBox.Show(未找到主页区域。试试另一个!);





}

}

catch(例外情况ex)

{

}

}

else if(comboBox1.SelectedIndex == 21)

{



试试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(select * from teacher where Baptism like'%+ searchtext +%'order by TeacherId,

con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet( );

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 22)

{



试试

$



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

select * from teacher,其中确认如'%+ searchtext +%'order by TeacherId,con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

}

}

catch(exception ex)

{

}

}

else if(comboBox1。 SelectedIndex == 23)

{



try

{

string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(select * from teacher where [Church Status] like'%} + searchtext +%',con );

SqlDataAdapter da = new SqlDataAdapter(cmd);


DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherDataGridView.DataSource = ds.Tables [ 老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{

MessageBox.Show(教堂状态未找到。试试另一个!);

}

}

catch(例外情况)

{

}

}

else if(comboBox1.SelectedIndex == 24)

{



尝试

{

string searchtext = textBox1.Text;

SqlCommand cmd =

新的SqlCommand(select * from teacher where Position like'%+ searchtext +%',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds,teacher);

teacherDataGridView.DataSource = ds。表格[老师];

listBox1.DataSource = ds.Tables [老师];

if(teacherDataGridView.RowCount == 1)

{



MessageBox.Show(找不到位置。试试另一个!);





}

}

catch(例外情况ex)

{

}

}

else if(comboBox1.SelectedIndex == 25)

{



试试

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(select * from teacher where Brigade like'%+ searchtext +%'order by TeacherId,

con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet( );

da.Fill(ds,老师);

teacherDataGridView.DataSource = ds.Tables [老师];
$ b$b listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{







}

}

catch (Exception ex)

{

}

}

else if (comboBox1.SelectedIndex == 26)

{



try

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

\"select * from teacher where [Christ Little Band] like ’%\" + searchtext + \"%’ order by TeacherId\", con);



SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, \"teacher\");

teacherDataGridView.DataSource = ds.Tables[\"teacher\"];

listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{







}

}

catch (Exception ex)

{

}

}

else if (comboBox1.SelectedIndex == 27)

{



try

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

\"select * from teacher where [ Girls Fellowship] like ’%\" + searchtext + \"%’ order by TeacherId\", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, \"teacher\");

teacherDataGridView.DataSource = ds.Tables[\"teacher\"];

listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{

}

}

catch (Exception ex)

{

}

}

else if (comboBox1.SelectedIndex == 28)

{



try

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(\"select * from teacher where Guild like ’%\" + searchtext + \"%’ order by TeacherId\", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, \"teacher\");

teacherDataGridView.DataSource = ds.Tables[\"teacher\"];

listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{







}

}

catch (Exception ex)

{

}

}

else if (comboBox1.SelectedIndex == 29)

{



try
$ b$b {



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

\"select * from teacher where [Men Fellowship] like ’%\" + searchtext + \"%’ order by TeacherId\", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, \"teacher\");

teacherDataGridView.DataSource = ds.Tables[\"teacher\"];

listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{

}

}

catch (Exception ex)

{

}

}

else if (comboBox1.SelectedIndex == 30)

{



try

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

\"select * from teacher where [Singing Band] like ’%\" + searchtext + \"%’ order by TeacherId\", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, \"teacher\");

teacherDataGridView.DataSource = ds.Tables[\"teacher\"];

listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{

}

}

catch (Exception ex)

{

}

}

else if (comboBox1.SelectedIndex == 31)

{



try

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

\"select * from teacher where [Sussana Wesley] like ’%\" + searchtext + \"%’ order by TeacherId\", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, \"teacher\");

teacherDataGridView.DataSource = ds.Tables[\"teacher\"];

listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{

}

}

catch (Exception ex)

{

}

}

else if (comboBox1.SelectedIndex == 32)

{



try

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

\"select * from teacher where [Women Fellowship] like ’%\" + searchtext + \"%’ order by TeacherId\", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, \"teacher\");

teacherDataGridView.DataSource = ds.Tables[\"teacher\"];

listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{







}

}

catch (Exception ex)

{

}

}

else if (comboBox1.SelectedIndex == 33)

{



try

{



string searchtext = textBox1.Text;

SqlCommand cmd =

new SqlCommand(

\"select * from teacher where [Youth Fellowship] like ’%\" + searchtext + \"%’ order by TeacherId\", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);



DataSet ds = new DataSet();

da.Fill(ds, \"teacher\");

teacherDataGridView.DataSource = ds.Tables[\"teacher\"];

listBox1.DataSource = ds.Tables[\"teacher\"];

if (teacherDataGridView.RowCount == 1)

{







}

}

catch (Exception ex)

{

}

}



}

Hello am inexperience programmer working on a database in sql using c#. in my form i have created a search field which search based on the text in combobox1 and textbox1. My problem is anything i search , the results does not link with my textboxes. it only links with datagridview and listbox but not textboxes. Before the search the datagridview and listbox link with my textboxes but anytime i search it does not.
this is my code for the search:
private void search()
{
string str = (@"Data Source=BROTHER-PC;Initial Catalog=iEMYS;Integrated Security=True");


SqlConnection con = new SqlConnection(str);
if (comboBox1.SelectedIndex == 0)
{
try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from teacher where TeacherId like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("Teacher ID was Not Found. Try Another!");


}
}
catch (Exception)
{

}
}

else if (comboBox1.SelectedIndex == 1)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand(
"select * from teacher where EMYSNO like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("EMYSNO was Not Found. Try Another!");


}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 2)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand(
"select * from teacher where [First Name] like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("First Name was Not Found. Try Another!");


}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 3)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from teacher where [Last Name] like '%" + searchtext + "%'",
con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("Last Name was Not Found. Try Another!");


}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 4)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from teacher where Sex like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("SexType was Not Found. Try Another!");


}
}
catch (Exception ex)
{
}

}
else if (comboBox1.SelectedIndex == 5)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from teacher where Hometown like '%" + searchtext + "%'",
con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("Hometown was Not Found. Try Another!");


}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 6)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from teacher where Region like '%" + searchtext + "%'",
con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("Region was Not Found. Try Another!");


}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 7)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where Single like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{



}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 8)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where Married like '%" + searchtext + "%' order by TeacherId",
con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{



}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 9)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Name Of Spouse] like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("Name Of Spouse was not found! Try again");

}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 10)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where Student like '%" + searchtext + "%' order by TeacherId",
con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 11)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where Institution like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
MessageBox.Show("Institution was not found! Try again");
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 12)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where Employed like '%" + searchtext + "%' order by TeacherId",
con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 13)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where Profession like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("Profession was not found! Try again");

}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 14)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where Unemployed like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{



}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 15)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where [Telephone #1] like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
MessageBox.Show("Telephone #1 was Not Found. Try Another!");
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 16)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Telephone #2] like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
MessageBox.Show("Telephone #2 was Not Found. Try Another!");
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 17)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from teacher where Email like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
MessageBox.Show("Email was Not Found. Try Another!");
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 18)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where [Postal Address] like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
MessageBox.Show("Postal Address was Not Found. Try Another!");
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 19)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where [Home Address] like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
MessageBox.Show("Home Address was Not Found. Try Another!");
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 20)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd = new SqlCommand(
"select * from teacher where [Home Area] like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("Home Area was Not Found. Try Another!");


}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 21)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where Baptism like '%" + searchtext + "%' order by TeacherId",
con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 22)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where Confirmation like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 23)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where [Church Status] like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
MessageBox.Show("Church Status was Not Found. Try Another!");
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 24)
{

try
{
string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where Position like '%" + searchtext + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{

MessageBox.Show("Position was Not Found. Try Another!");


}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 25)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where Brigade like '%" + searchtext + "%' order by TeacherId",
con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{



}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 26)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Christ Little Band] like '%" + searchtext + "%' order by TeacherId", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{



}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 27)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Girls Fellowship] like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 28)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand("select * from teacher where Guild like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{



}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 29)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Men Fellowship] like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 30)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Singing Band] like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 31)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Sussana Wesley] like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{
}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 32)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Women Fellowship] like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{



}
}
catch (Exception ex)
{
}
}
else if (comboBox1.SelectedIndex == 33)
{

try
{

string searchtext = textBox1.Text;
SqlCommand cmd =
new SqlCommand(
"select * from teacher where [Youth Fellowship] like '%" + searchtext + "%' order by TeacherId", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds, "teacher");
teacherDataGridView.DataSource = ds.Tables["teacher"];
listBox1.DataSource = ds.Tables["teacher"];
if (teacherDataGridView.RowCount == 1)
{



}
}
catch (Exception ex)
{
}
}

}

推荐答案

这篇关于如何将datagridview,listbox链接到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 05:21