Your Ad Here

Data Class In C# (Access)

I m Takin the example of Ms-access u can take Sql also

    OleDbDataAdapter da;                                     
    OleDbConnection con ;     
    OleDbCommand cmd = new OleDbCommand();
    DataSet ds = new DataSet();
    DataTable dt = new DataTable()


Now comes the main code . Here the command as u can see remains as a string .This save u writing the whole code . This is useful when databases are used frequently in the website . It makes the code look more Ideal ...


 public void ConnectDataBaseToInsert(string Query)     
    {                                                                                
        con = new OleDbConnection("connection Strings");
        cmd.CommandText = Query;                                
        cmd.Connection = con;                                         
        da = new OleDbDataAdapter(cmd);                     
        con.Open();                                                         
        cmd.ExecuteNonQuery();                                    
        con.Close();                                                          
    }


Add this code in default.aspx.cs
DataBaseClass dbClass = new DataBaseClass();


Declare the string in the same file