我如何更改不同按钮的查询 [英] how i change query for different button

查看:80
本文介绍了我如何更改不同按钮的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当不同的按钮按下查询更改和其他代码保持相同时如何进行查询检查。因为我对不同的按钮有不同的查询

请帮帮我... ??







how to make check in query when different button press only query changes and other code remain same..because i have different queries for different button
please help me with that..??



public static DataTable Getafile(int id)
        {
            DataTable dt = new DataTable();
            using (SqlConnection con = new SqlConnection())
            {
                OpenConnection(con);
                SqlCommand com = new SqlCommand();
                com.Connection = con;
                com.CommandTimeout = 0;
                com.CommandText = "SELECT ID, Name, [Content], size, data FROM Connectivity where ID=@ID";
                com.CommandType = CommandType.Text;
                SqlDataAdapter da = new SqlDataAdapter();
                com.Parameters.Add("@ID", SqlDbType.Int);
                com.Parameters["@ID"].Value = id;
                da.SelectCommand = com;
                da.Fill(dt);
                con.Close();


            }
            return dt;
        }

推荐答案

如前所述,写一个方法,比如说 executeMyQuery 将查询字符串作为单个参数,在此方法中输入执行查询所需的所有代码。然后从不同的按钮单击处理程序调用它(每个处理程序应传递自己的查询字符串)。
As already suggested, write a method, say executeMyQuery taking, as single parameter, the query string, put in such method all the required code for executing the query. Then call it from the different button click handlers (each handler should pass its own query string).


您可以参考以下链接。我还没有验证,但我认为这对你来说很好。



SqlWhereBuilder ASP.NET服务器控件
You may refer to the below link. I haven''t verified it,but i think it would be a nice for you.

SqlWhereBuilder ASP.NET Server Control


这篇关于我如何更改不同按钮的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆