Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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..??



C#
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;
        }
Posted
Updated 12-May-13 20:54pm
v2
Comments
Thanks7872 13-May-13 2:56am    
Write function that will handle common tasks among all the buttons such as opening connection.
fak_farrukh 13-May-13 3:13am    
cant understand
Sergey Alexandrovich Kryukov 13-May-13 2:56am    
What's the problem?
—SA
fak_farrukh 13-May-13 3:09am    
i only want this "SELECT ID, Name, [Content], size, data FROM Connectivity where ID=@ID"; query changes to this "SELECT ID, Name, [Content], size, data FROM IN where ID=@ID"; query when different button is press
i cant understand how to do that??

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).
 
Share this answer
 
Comments
Pranit Kothari 13-May-13 3:53am    
5!
CPallini 13-May-13 4:17am    
Thank you.
Sergey Alexandrovich Kryukov 13-May-13 3:56am    
OP already said "cannot understand", it may happen again. But a 5 from me.
—SA
CPallini 13-May-13 4:17am    
Thank you.
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900