how to make the dynamic query using c sharp
  • Hi i want the user is selected multiple column at run time so i want to insert the recort in sql.
  • 1 Comment sorted by
  • Vote Up0Vote Down WaqasWaqas
    172.00 Karma Accepted Answer
    Hi may be your Query like this



    strin Query ="insert into tableName (";
    if(textbox1.Text.Length>0)
    {
    Query=Query+"ColumnName1";
    }
    if(textbox2.Text.Length>0)
    {
    Query=Query+",ColumnName2";
    }
    Query=Query+")";
    //now insert values
    if(textbox1.Text.Length>0 or textbox2.Text.Length>0)
    {
    Query=Query+" Values(";
    if(textbox1.Text.Length>0)
    {
    Query=Query+"'"+textbox1.Text+"'";
    }
    if(textbox2.Text.Length>0)
    {
    Query=Query+",'"+textbox2.Text+"'";
    }
    Query=Query+")";
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week