那么我如何在C#中的Windows窗体中执行此操作在Visual Studio 2010中? [英] So How Can I Do This In Windows Form In C# In Visual Studio 2010 ?
本文介绍了那么我如何在C#中的Windows窗体中执行此操作在Visual Studio 2010中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有不同类型参数的组合框,并且附近有一个文本框,并且有一个查找按钮。
假设组合框具有名称,年龄,性别以及我是否会选择名称在组合框中所以在文本框中我只能输入一些名称并通过单击旁边的查找按钮从数据库中找到该特定记录
所以我如何在Visual Studio 2010中以C#的形式执行此操作? div class =h2_lin>解决方案
尝试:
如果( myComboBox.Text == 名称)
{
使用(SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
使用(SqlCommand cmd = new SqlCommand( SELECT Id,Description FROM myTable WHERE NameColumn LIKE'%'+ @NAME +'%',con))
{
cmd.Parameters.AddWithValue( @ NAME,myTextBox.Text);
使用(SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int id =( int )reader [ Id];
string desc =( string )reader [ 描述];
Console.WriteLine( ID:{0} \ n {1}, iD,desc);
}
}
}
}
}
I have a combo box having different type of parameters and there is a textbox near to it and a find button is there .
suppose combobox having name,age,gender and if i will select name in combobox so in textbox i can only type some name and find that particular record from database by clicking find button next to it
so how can i do this in windows form in C# in visual studio 2010 ?
解决方案
Try:
if (myComboBox.Text == "Name") { using (SqlConnection con = new SqlConnection(strConnect)) { con.Open(); using (SqlCommand cmd = new SqlCommand("SELECT Id, Description FROM myTable WHERE NameColumn LIKE '%' + @NAME + '%'", con)) { cmd.Parameters.AddWithValue("@NAME", myTextBox.Text); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int id = (int)reader["Id"]; string desc = (string)reader["Description"]; Console.WriteLine("ID: {0}\n {1}", iD, desc); } } } } }
这篇关于那么我如何在C#中的Windows窗体中执行此操作在Visual Studio 2010中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文