ado.net - call component from form to class and save data back to table -


i working on ado.net project,, used have separate classes codes ,,, trying learn more local databases stock when tried call class contain sql commands ,,, please have code commented stock

    namespace maintenance     {         public partial class registerreports : form         {             private void btnsave_click(object sender, eventargs e)             {                 //the code works if exists here                 /**                     conn.open();                     com.parameters.addwithvalue("@reportid",                     tbreportidox.text);                     com.executenonquery();                     conn.close();                 **/             }         }     } 

    class reporttablesql      {         public void reporttable()         {             string connectionstring = connectionstring = "data source=             ..//..//maintenancedb.sdf";             sqlceconnection conn = new sqlceconnection(connectionstring);              using (sqlcecommand com = new sqlcecommand("insert             reportform values(@reportid)", conn))             {                 // if call method class registerreports : form                 // doesn't recognise tbreportidox.text                 //it isn't exist in class                  /**                     conn.open();                     com.parameters.addwithvalue("@reportid",                     tbreportidox.text);                     com.executenonquery();                     conn.close();                 **/             }         }     } 

thank

what can pull tbreportidox.text parameters method, is

public void reporttable(string reportname) {        ...     com.parameters.addwithvalue("@reportid",    reportname);     ... } 

and on button click

private void btnsave_click(object sender, eventargs e) {         // resolve instance of reporttablesql class         // example through: new reporttablesql();         var reportgenerator = new reporttablesql();         reportgenerator.reporttable(tbreportidox.text); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -