Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
why is this showing like this and what's the error

What I have tried:

<pre lang="CoffeeScript"><pre lang="C#">
<pre><pre>
public partial class Gridviewdemo : System.Web.UI.Page
   {
       private string strConnectionString = ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;
       private SqlCommand _sqlCommand;
       private SqlDataAdapter _sqlDataAdapter;
       DataSet _dtSet;
       protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               BindEmployeeData();

           }
           btnUpdate.Visible = false;
           btnAddEmployee.Visible = true;

       }
       private static void ShowAlertMessage(string error)
       {
           System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;
           if (page != null)
           {
               error = error.Replace("'", "\'");
               System.Web.UI.ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + error + "');", true);
           }
       }
       public void CreateConnection()
       {
           SqlConnection _sqlConnection = new SqlConnection(strConnectionString);
           _sqlCommand = new SqlCommand();
           _sqlCommand.Connection = _sqlConnection;
       }
       public void OpenConnection()
       {
           _sqlCommand.Connection.Open();
       }
       public void CloseConnection()
       {
           _sqlCommand.Connection.Close();
       }
       public void DisposeConnection()
       {
           _sqlCommand.Connection.Dispose();
       }
       public void BindEmployeeData()
       {
           try
           {
               CreateConnection();
               OpenConnection();
               _sqlCommand.CommandText = "Sp_GridCrud";
               _sqlCommand.CommandType = CommandType.StoredProcedure;
               _sqlCommand.Parameters.AddWithValue("@Event", "Select");
               _sqlDataAdapter = new SqlDataAdapter(_sqlCommand);
               _dtSet = new DataSet();
               _sqlDataAdapter.Fill(_dtSet);
               grvEmployee.DataSource = _dtSet;
               grvEmployee.DataBind();
           }
           catch (Exception ex)
           {
               Response.Redirect("The Error is " + ex);
           }
           finally
           {
               CloseConnection();
               DisposeConnection();
           }
            protected void btnAddEmployee_Click(object sender, EventArgs e)
       {
           try
           {
               CreateConnection();
               OpenConnection();
               _sqlCommand.CommandText = "Sp_GridCrud";
               _sqlCommand.CommandType = CommandType.StoredProcedure;
               _sqlCommand.Parameters.AddWithValue("@Event", "Add");
               _sqlCommand.Parameters.AddWithValue("@FirstName", Convert.ToString(txtFirstName.Text.Trim()));
               _sqlCommand.Parameters.AddWithValue("@LastName", Convert.ToString(txtLastName.Text.Trim()));
               _sqlCommand.Parameters.AddWithValue("@PhoneNumber", Convert.ToString(txtPhoneNumber.Text.Trim()));
               _sqlCommand.Parameters.AddWithValue("@EmailAddress", Convert.ToString(txtEmailAddress.Text.Trim()));
               _sqlCommand.Parameters.AddWithValue("@Salary", Convert.ToDecimal(txtSalary.Text));
               int result = Convert.ToInt32(_sqlCommand.ExecuteNonQuery());
               if (result > 0)
               {

                   ShowAlertMessage("Record Is Inserted Successfully");
                   BindEmployeeData();
                   ClearControls();
               }
               else
               {

                   ShowAlertMessage("Failed");
               }
           }
           catch (Exception ex)
           {

               ShowAlertMessage("Check your input data");

           }
           finally
           {
               CloseConnection();
               DisposeConnection();
           }
       }

       public void ClearControls()
       {
           txtFirstName.Text = "";
           txtLastName.Text = "";
           txtPhoneNumber.Text = "";
           txtEmailAddress.Text = "";
           txtSalary.Text = "";
       }

       protected void grvEmployee_RowEditing(object sender, GridViewEditEventArgs e)
       {
               btnAddEmployee.Visible = false;
               btnUpdate.Visible = true;

               int RowIndex = e.NewEditIndex;
               Label empid = (Label)grvEmployee.Rows[RowIndex].FindControl("lblEmpId");
               Session["id"] = empid.Text;

               txtFirstName.Text = ((Label)grvEmployee.Rows[RowIndex].FindControl("lblFirstName")).Text.ToString();
               txtLastName.Text = ((Label)grvEmployee.Rows[RowIndex].FindControl("lblLastName")).Text.ToString();
               txtPhoneNumber.Text = ((Label)grvEmployee.Rows[RowIndex].FindControl("lblPhoneNumber")).Text.ToString();
               txtEmailAddress.Text = ((Label)grvEmployee.Rows[RowIndex].FindControl("lblEmailAddress")).Text.ToString();
               txtSalary.Text = ((Label)grvEmployee.Rows[RowIndex].FindControl("lblSalary")).Text.ToString();

       }

       protected void grvEmployee_RowDeleting(object sender, GridViewDeleteEventArgs e)
       {
           try
           {
               CreateConnection();
               OpenConnection();
               Label id = (Label)grvEmployee.Rows[e.RowIndex].FindControl("lblEmpId");
               _sqlCommand.CommandText = "Sp_GridCrud";
               _sqlCommand.Parameters.AddWithValue("@Event", "Delete");
               _sqlCommand.Parameters.AddWithValue("@EmpId", Convert.ToInt32(id.Text));
               _sqlCommand.CommandType = CommandType.StoredProcedure;
               int result = Convert.ToInt32(_sqlCommand.ExecuteNonQuery());
               if (result > 0)
               {

                   ShowAlertMessage("Record Is Deleted Successfully");
                   grvEmployee.EditIndex = -1;
                   BindEmployeeData();
               }
               else
               {
                   lblMessage.Text = "Failed";
                   lblMessage.ForeColor = System.Drawing.Color.Red;
                   BindEmployeeData();
               }
           }
           catch (Exception ex)
           {

               ShowAlertMessage("Check your input data");
           }
           finally
           {
               CloseConnection();
               DisposeConnection();
           }
       }

       protected void grvEmployee_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
       {
           grvEmployee.EditIndex = -1;
           BindEmployeeData();
       }

       protected void grvEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
       {
           grvEmployee.PageIndex = e.NewPageIndex;
           BindEmployeeData();
       }

       protected void btnReset_Click(object sender, EventArgs e)
       {
           ClearControls();
       }

       protected void btnUpdate_Click(object sender, EventArgs e)
       {
           try
           {

                   CreateConnection();
                   OpenConnection();

                   _sqlCommand.CommandText = "Sp_GridCrud";
                   _sqlCommand.CommandType = CommandType.StoredProcedure;
                   _sqlCommand.Parameters.AddWithValue("@Event", "Update");
                   _sqlCommand.Parameters.AddWithValue("@FirstName", Convert.ToString(txtFirstName.Text.Trim()));
                   _sqlCommand.Parameters.AddWithValue("@LastName", Convert.ToString(txtLastName.Text.Trim()));
                   _sqlCommand.Parameters.AddWithValue("@PhoneNumber", Convert.ToString(txtPhoneNumber.Text.Trim()));
                   _sqlCommand.Parameters.AddWithValue("@EmailAddress", Convert.ToString(txtEmailAddress.Text.Trim()));
                   _sqlCommand.Parameters.AddWithValue("@Salary", Convert.ToDecimal(txtSalary.Text));
                   _sqlCommand.Parameters.AddWithValue("@EmpId", Convert.ToDecimal(Session["id"]));
Posted
Updated 4-Jun-22 22:54pm
Comments
Nirav Prabtani 19-Jan-22 3:54am    
Check for the brackets properly, it seems you have missed closing the bracket of BindEmployeeData function
Manojkumar-dll 19-Jan-22 4:00am    
done !! but my problem is with the CS0106 the modifier 'protected' is not valid for this item

BindEmployeeData is missing the final closing curly bracket:
       public void BindEmployeeData()
       {
           try
           {
...
           }
           catch (Exception ex)
           {
...
           }
           finally
           {
...
           }
            protected void btnAddEmployee_Click(object sender, EventArgs e)
       {
which means that it assumes btnAddEmployee_Click is a part of the function, and no access modifier is legal there.

Fix that, then reindent your code (VS will do it for you if the brackets are all correct) with "CTRL+K D" and that should fix it. If VS won't, then the brackets aren't correct, so start by looking at where the first error occurs and check the method above that.
Since you code isn't complete, the first fault is the only one we can find for you - you need to get used to looking for these problems yourself, as you will see a lot more of them in the future (we all do), and it's a whole load quicker to be able to spot them yourself instead of waiting for others to do it for you!
 
Share this answer
 
public static void main (Args _args)
{
TmpFrmVirtual tmpFrmVirtualVend;
PurchFormLetter_Invoice purchFormLetter;
VendPackingSlipJour vendPackingSlipJour;
SysQueryRun chooseLinesQuery;
SysQueryRun chooseLinesPendingInvoiceQuery;
container conTmpFrmVirtual;
List selectedList = new List(Types::Record);
PurchId purchId = "PO00001" ; //Purchase order number
PackingSlipId packingSlipId = "PCK0001"; //Product receipt number

select firstonly vendPackingSlipJour
where vendPackingSlipJour.PurchId == purchId
&& vendPackingSlipJour.PackingSlipId == packingSlipId;

if (vendPackingSlipJour)
{
tmpFrmVirtualVend.clear();
tmpFrmVirtualVend.TableNum = vendPackingSlipJour.TableId;
tmpFrmVirtualVend.RecordNo = vendPackingSlipJour.RecId;
tmpFrmVirtualVend.NoYes = NoYes::Yes;
tmpFrmVirtualVend.Id = vendPackingSlipJour.PurchId;
tmpFrmVirtualVend.insert();
}

chooseLinesQuery = new SysQueryRun(queryStr(PurchUpdate));
chooseLinesQuery.query().addDataSource(tableNum(VendInvoiceInfoTable)).enabled(false);

// chooseLinesPendingInvoiceQuery needs to be initialized, although it will not be used
chooseLinesPendingInvoiceQuery = new SysQueryRun(queryStr(PurchUpdatePendingInvoice));
chooseLinesPendingInvoiceQuery.query().dataSourceTable(tableNum(PurchTable)).addRange(fieldNum(PurchTable,PurchId)).value(queryValue(''));

purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.chooseLinesQuery (chooseLinesQuery);
purchFormLetter.parmQueryChooseLinesPendingInvoice(chooseLinesPendingInvoiceQuery);
purchFormLetter.purchTable (PurchTable::find(PurchId));
purchFormLetter.transDate (systemDateGet());
purchFormLetter.parmParmTableNum (strFmt("%1",packingSlipId)); //This is invoice number
purchFormLetter.printFormLetter (NoYes::No);
purchFormLetter.sumBy (AccountOrder::Auto);
purchFormLetter.specQty (PurchUpdate::PackingSlip);

while select tmpFrmVirtualVend
{
selectedList.addEnd(tmpFrmVirtualVend);
conTmpFrmVirtual = selectedList.pack();
}
purchFormLetter.selectFromJournal(conTmpFrmVirtual);
purchFormLetter.reArrangeNow(true);
purchFormLetter.run();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900