form上数据查询有关问题
form上数据查询问题
用 C#实现我在form上有两个textbox 一为X 一个为Y 然后还有一个richtextbox,要求是在X中输入一个值 在Y中也输入一个值 在数据库中查询 然后在richtextbox中 显示对应的值出来 数据库名为dao 求大神代码
------解决方案--------------------
select * from 表 where x='" + x.Text + "' and y='"+y.Text+"'"
用 C#实现我在form上有两个textbox 一为X 一个为Y 然后还有一个richtextbox,要求是在X中输入一个值 在Y中也输入一个值 在数据库中查询 然后在richtextbox中 显示对应的值出来 数据库名为dao 求大神代码
------解决方案--------------------
select * from 表 where x='" + x.Text + "' and y='"+y.Text+"'"
string queryString = select * from 表 where x='" + x.Text + "' and y='"+y.Text+"'";
using (SqlConnection connection = new SqlConnection( connectionString))
{
SqlCommand command = new SqlCommand( queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
richtextbox.Text=reader[0].ToString();
}
}
finally
{
}
}
}