how can i save multiple record in single click using user define data type in SQL
i am having problem in selecting the value in gridview using checkbox

here my code

View

// View LAyer 
    protected void imgbtnSave_Click(object sender, EventArgs e)
        {

            DataTable dtTable = new DataTable();
            DataRow dtRow = dtTable.NewRow();
           for (int i = 0; i < gvTaggingAccounts.Rows.Count; i++)
              {
                  GridViewRow row = gvTaggingAccounts.Rows[i];

                  bool isChecked = ((CheckBox)row.FindControl("chkTypes")).Checked;

               if(isChecked)
                {
                    dtRow["AccountNUM"] = gvTaggingAccounts.Rows[i].Cells[1].Text; //having error here.. not belong to the table.. 
                    dtRow["Accoutname"] = gvTaggingAccounts.Rows[i].Cells[2].Text;
                   dtTable.Rows.Add(dtRow);
                    _taggingAccountsManager.InsertAXPerDepartment();
                } 
            }
        }
       // DLSQL Layer 


            public override bool InsertAXPerDepartment()
            {
                var isSuccess = false;
                try
                {

                    _sqlHelper.CreateConnection();
                    _sqlHelper.CreateCommand("usp_InsertAXPerDepartment");

                    _sqlHelper.ExecuteNonQuery();

                }
                catch (Exception ex)
                {

                    ErrorHandler.Handle(ex);
                    OnRaiseErrorOccuredEvent(this, new ErrorEventArgs(ex));

                }
                finally
                {
                    _sqlHelper.CloseConnection();

                }
                return isSuccess;

            }



            public override bool InsertAXPerDepartment(DataTable AcctTag)
            {
                var isSuccess = false;

                try
                {

                    _sqlHelper.CreateConnection();
                    _sqlHelper.CreateCommand("usp_InsertAXPerDepartment");
                    _sqlHelper.Command.CommandType = CommandType.StoredProcedure;
                    _sqlHelper.Command.Parameters.Add("@AcctTag" ,SqlDbType.Structured);
                    SqlParameter Param = _sqlHelper.Command.Parameters.Add("@AcctTag", SqlDbType.Structured);
                    Param.Value = AcctTag;



                    ErrorHandler.Handle(ex);
                    OnRaiseErrorOccuredEvent(this, new ErrorEventArgs(ex));

                }
                finally
                {
                    _sqlHelper.CloseConnection();

                }
                return isSuccess;
            }


            my user define table is working together with the stored proc..

            anyone can solve this problem.. 


            thanks 




    protected void imgbtnSave_Click(object sender, EventArgs e)
        {

            DataTable dtTable = new DataTable();
            DataRow dtRow = dtTable.NewRow();
           for (int i = 0; i < gvTaggingAccounts.Rows.Count; i++)
              {
                  GridViewRow row = gvTaggingAccounts.Rows[i];

                  bool isChecked = ((CheckBox)row.FindControl("chkTypes")).Checked;

               if(isChecked)
                {
                    dtRow["AccountNUM"] = gvTaggingAccounts.Rows[i].Cells[1].Text; //having error here.. not belong to the table.. 
                    dtRow["Accoutname"] = gvTaggingAccounts.Rows[i].Cells[2].Text;
                   dtTable.Rows.Add(dtRow);
                    _taggingAccountsManager.InsertAXPerDepartment();
                } 
            }
        }
        DLSQL


            public override bool InsertAXPerDepartment()
            {
                var isSuccess = false;
                try
                {

                    _sqlHelper.CreateConnection();
                    _sqlHelper.CreateCommand("usp_InsertAXPerDepartment");

                    _sqlHelper.ExecuteNonQuery();

                }
                catch (Exception ex)
                {

                    ErrorHandler.Handle(ex);
                    OnRaiseErrorOccuredEvent(this, new ErrorEventArgs(ex));

                }
                finally
                {
                    _sqlHelper.CloseConnection();

                }
                return isSuccess;

            }



            public override bool InsertAXPerDepartment(DataTable AcctTag)
            {
                var isSuccess = false;

                try
                {

                    _sqlHelper.CreateConnection();
                    _sqlHelper.CreateCommand("usp_InsertAXPerDepartment");
                    _sqlHelper.Command.CommandType = CommandType.StoredProcedure;
                    _sqlHelper.Command.Parameters.Add("@AcctTag" ,SqlDbType.Structured);
                    SqlParameter Param = _sqlHelper.Command.Parameters.Add("@AcctTag", SqlDbType.Structured);
                    Param.Value = AcctTag;



                    ErrorHandler.Handle(ex);
                    OnRaiseErrorOccuredEvent(this, new ErrorEventArgs(ex));

                }
                finally
                {
                    _sqlHelper.CloseConnection();

                }
                return isSuccess;
            }

I could be completely wrong here as not tried any of code only looked at it,

But shouldn't ((CheckBox)row.FindControl("chkTypes")).Checked;

Be (CheckBox)(row.FindControl("chkTypes")).Checked;

So that is casts the object found as a CheckBox and not the row?

Quoted Text Here

I could be completely wrong here as not tried any of code only looked at it,

But shouldn't ((CheckBox)row.FindControl("chkTypes")).Checked;

Be (CheckBox)(row.FindControl("chkTypes")).Checked;

So that is casts the object found as a CheckBox and not the row?

No. The dot operator takes precedence over the cast operator. If you did it that way, first of all, it would fail since Control does not have a Checked property. But, it would attempt to cast the Checked property to a CheckBox.

@nmaillet are you sure..? coz i am having an error right now saying missing assembly reference..

Could you be more specific? What does the exception say? What line of code is it referring too? etc...

Also, if you want to be sure isChecked is being correct set, add using System.Diagnostics then add Debug.WriteLine(isChecked); (if you are using an IDE that supports it). You can add some more information so the output is more meaningful, and shows which specific rows it is correctly getting isChecked from.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.