如何从表中搜索值. [英] How to search values from table.
本文介绍了如何从表中搜索值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从表中搜索值.我有文本框和按钮.当我在文本框中输入字符串并按下按钮时,应显示表中所有匹配的记录.请帮助我.
How to search values from table. I have textbox and button. when i enter string in textbox and press button all matching records from table should display. Please help me.
推荐答案
这是什么?
您将其标记为C#和SQL.您想如何搜索.
您必须参考:
如何问一个好问题? [在论坛中发布问题的一些准则 [ ^ ]
在发布任何问题之前,请先尝试一下.访问google,找到一些解决方案,如果您遇到困难,请在此处发布您的问题.
请参考:搜索文本框并绑定Gridview使用Asp.net [ ^ ]
看看 ^ ]相同.
始终先尝试使用google,然后在此处发布您的问题. Google比其他任何选择都更好.
祝您编程愉快!!
What is this?
You tagged it C# and SQL. How you want to search.
You must refer:
How to ask a good question?[^]
ans also Some guidelines for posting questions in the forums[^]
Before posting any question give a try by your side first. Visit google, find some solutions and if you get stuck''d somewhere then post your question here.
Refer: Search into Textbox and Bind Gridview using Asp.net[^]
Have a look on google[^] for same.
Always try google first, then post your questions here. Google is better option than anything else.
Happy coding.!
您需要了解WHERE 条款 [在SQL中 ^ ].
许多条件,例如BETWEEN, LIKE
等,提供了在查询中编写过滤条件的方法.
您需要阅读一些有关SQL的内容,以了解有关搜索/过滤值的更多信息.
You need to learn about the WHERE clause[^] in SQL.
A number of conditions likeBETWEEN, LIKE
etc provide ways to write filter conditions in a query.
You will need to do some reading on SQL to learn more about searching / filtering values.
您好,请尝试
创建存储过程
hi try this
create stored procedure
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[usp_SearchRoomDetails]
@RoomNo varchar(50)
AS
BEGIN
SET NOCOUNT ON;
SELECT * from RoomDetailsTab where RoomNo=@RoomNo
END
并在页面中将此sp称为
and call this sp in page
protected void Search_Click(object sender, ImageClickEventArgs e)
{
string RoomNo = "";
RoomNo = txtRoomNo.Text;
SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());
cnn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_SearchRoomDetails";
SqlParameter pRoomNo = new SqlParameter("@RoomNo", SqlDbType.VarChar, 50);
pRoomNo.Value = RoomNo;
cmd.Parameters.Add(pRoomNo);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
//if u want to display searched record in textbox
txtRNo.Text = dt.Rows[0]["RoomNo"].ToString();
txtDetails.Text = dt.Rows[0]["Details"].ToString();
}
if (dt.Rows.Count == 0)
{
//if record is empty will show message
Response.Write("No result found");
}
cnn.Close();
}
试试这个
快乐的编码.
try this
happy coding..
这篇关于如何从表中搜索值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文