kevin

kevin

  • NA
  • 23
  • 16.2k

c# Access Db,no value given for one or more required param

Feb 8 2016 6:34 AM

 

class AssetRegister
    {
        #region fields
       public OleDbDataAdapter da;
       public OleDbDataAdapter da2;
       public DataTable dt;
       public DataTable dt2;
       public  OleDbCommand cmd;
       public  OleDbCommand cmd2;
       public  OleDbCommandBuilder cmb;
       public  OleDbCommandBuilder cmb2;
       public string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\AssetReg.accdb";
       public string sql1;
       public string sql2;
       BindingSource bnd = new BindingSource();
       BindingSource bnd2 = new BindingSource();

       public DataSet ds;
       public DataSet ds2;
       public OleDbConnection con;
       public DataRow dr;
       public DataRow drUpdate;
       ToolTip toolt;
        #endregion

        #region Connection Method
        /*--------------------------------------------------------------------------------
         * public method
         * Overloaded : No
         * Parameters : No
         * Return Value : bool(true or false)
         * Purpose: creates a connection to the database,a DataAdapter,
              a DataSet and returns true if all ok otherwise false
         * ------------------------------------------------------------------------------*/
      
        public bool FnGetDataConnection()
        {
            try
            {
                con = new OleDbConnection(conString);
                this.sql1 = "Select * from User_Details order by Rank,Initials and Surname";
                con.Open();
                cmd = new OleDbCommand(sql1, con);
                da = new OleDbDataAdapter(cmd);
                cmb = new OleDbCommandBuilder(da);
                ds = new DataSet();
                da.Fill(ds, "User_Details");
                dt = ds.Tables["User_Details"];
                bnd.DataSource = ds.Tables["User_Details"];
                toolt = new ToolTip();
               
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error",ex.Message);
                //conection failed
                return false;
            }//end catch

            //connection ok
            return true;
        }


        #endregion
        #region Connection Function for Hardware Tab
        //This Function establish connection for HardwareInfor Tab only
        public bool FnGetDataConnection2(string rank,string initSurname,string fNumber)
        {
            this.sql2 = "select * from User_Details" + "inner join Hardware_Info on Hardware_Info.Force Number = User_Details.Force Number" +
                "where (User_Details.Rank='" + rank + "') or (User_Details.Initials and Surname='" + initSurname + "')" + "order by               User_Details.Rank,User_Details.Initials and Surname ";

            try
            {
                con = new OleDbConnection(conString);
                da = new OleDbDataAdapter(this.sql2, con);
                //refresh row in dataset
                ds = new DataSet();
                da.Fill(ds, "User_Details");

            }//end try
            catch (Exception ex)
            {
                MessageBox.Show("Error", "Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }//catch

            //connection ok
            return true;
        }
        #endregion

    }//end class

}//end namespace



private void Asset_Register_Load(object sender, EventArgs e)
        {
            //check connection to database
            if (this.assetCon.FnGetDataConnection())
            {
                this.assetdg.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkGreen;
                this.assetdg.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                this.assetdg.DataSource = assetCon.ds.Tables["User_Details"];
                //invoke method for databindings for textboxes
                fnGetDataBindingForUser_Details();
                //set currencyManager
               fnSetCurrencyManger();
            }
            else
            {
                //connection failed
                MessageBox.Show("Connection Failed","Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();//exit program
            }
            //Here  i will include function calls and data connetion and databinding function to textboxes
           // string sql2 = "Select* from Hardware_Info";
            
               // cmd2 = new OleDbCommand(sql2, con)
               // da2 = new OleDbDataAdapter(cmd2);
              
               // cmb2 = new OleDbCommandBuilder(da2);
            
                //ds2 = new DataSet();
               
             
               /* bnd2.DataSource = ds2.Tables["Hardware_Info"];
               // toolt = new ToolTip();
                this.assetdg.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkSeaGreen;
                this.hwdg.AlternatingRowsDefaultCellStyle.BackColor = Color.Aquamarine;
                con.Close();
                assetdg.DataSource = bnd;
                hwdg.DataSource = bnd2;*/
              
        }
      

 Hi I'm busy developing Asset management application using c# and access database, when I run the application I receive the following

 

message->"NO VALUE GIVEN FOR ONE OR MORE REQUIRED PARAMETERS",I'm struggling to trace the problem please can anyone assist,i'm trying to join two tables i.e Parent and child if I update record from parent the related record in child table must also be updated.

 

Attachment: test.zip

Answers (1)