[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

DataGrid Update

Asked by farquest786 in C# Programming Language

Tags: datagrid, update

Hi,
I have this code for my DataGrid_Update where in I am trying to update a field, which is kind of acting up, as it is urgent if someone can take a lokk at it i will really appreciate it.

Thanks,

Here is the whole code.

      private void Page_Load(object sender, System.EventArgs e)
            {
                  DateTime DtDate = new DateTime();
                  DtDate = DateTime.Now;
                  FText.Value = DtDate.ToShortDateString();
                  TText.Value = DtDate.AddDays(13).ToShortDateString();
            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_Cancel);
                  this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_Edit);
                  this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_Update);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            public void GetRecs_Click(object sender, System.EventArgs e)
            {
                  BindData();
            }

      
            private void DataGrid1_Edit(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  DataGrid1.EditItemIndex = e.Item.ItemIndex;
                  BindData();
            }

            private void DataGrid1_Cancel(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  DataGrid1.EditItemIndex = -1;
                  BindData();
            }

            private void DataGrid1_Select(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  Label2.Text +=DataGrid1.SelectedItem.Cells[0].Text;
                  //BindData();
            }

            private void DataGrid1_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  string StrConnection;
                  System.Web.UI.WebControls.TextBox cName = new System.Web.UI.WebControls.TextBox();
                  cName = (System.Web.UI.WebControls.TextBox)e.Item.Cells[6].Controls[0];
StrConnection = "Password=xxx;Persist Security Info=True;User ID=sa;Initial Catalog=Duc;Data Source=SQL001";
                  SqlConnection myConnection = new SqlConnection(StrConnection);
                  SqlCommand myCommand = new SqlCommand("SP_UpdateQty", myConnection);
                  myCommand.CommandType = CommandType.StoredProcedure;
//                  myCommand.Parameters.Add(new SqlParameter("@product", SqlDbType.VarChar,20));
//                  myCommand.Parameters["@product"].Value = cName.Text;
//                  myCommand.Parameters.Add(new SqlParameter("@harvest_date", SqlDbType.DateTime,8));
//                  myCommand.Parameters["@harvest_date"].Value = cName.Text;
//                  myCommand.Parameters.Add(new SqlParameter("@prod_size", SqlDbType.Int,4));
//                  myCommand.Parameters["@prod_size"].Value = cName.Text;
            myCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Int,4));
                  myCommand.Parameters["@quantity"].Value = cName.Text;
                  myConnection.Open();
                  myCommand.ExecuteNonQuery();
                  myConnection.Close();
                  DataGrid1.EditItemIndex = -1;
                  BindData();
            }

            public void BindData()
            {
                  string StrConnection;
string selectCmd = "select * from harvest1 where quantity > 0 and product = @product and harvest_Date Between @FText and @TText";

StrConnection = "Password=xxx;Persist Security Info=True;User ID=sa;Initial Catalog=Duc;Data Source=SQL001";
                  SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, StrConnection);

      myCommand.SelectCommand.Parameters.Add(new SqlParameter("@product", SqlDbType.VarChar, 20));
                  myCommand.SelectCommand.Parameters["@product"].Value = MySelect.Value;

      myCommand.SelectCommand.Parameters.Add(new SqlParameter("@FText", SqlDbType.SmallDateTime, 8));
                  myCommand.SelectCommand.Parameters["@FText"].Value = FText.Value;

      myCommand.SelectCommand.Parameters.Add(new SqlParameter("@TText", SqlDbType.SmallDateTime, 8));
                  myCommand.SelectCommand.Parameters["@TText"].Value = TText.Value;

                  DataSet ds = new DataSet();
                  myCommand.Fill(ds, "Harvest1");

                  DataGrid1.DataSource = ds.Tables["Harvest1"].DefaultView;
                  DataGrid1.DataBind();

            }
[+][-]11/29/05 11:00 AM, ID: 15382497Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/29/05 11:04 AM, ID: 15382521Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/29/05 11:07 AM, ID: 15382548Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/29/05 11:14 AM, ID: 15382596Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/29/05 11:16 AM, ID: 15382610Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/29/05 11:31 AM, ID: 15382726Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/29/05 11:34 AM, ID: 15382747Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/29/05 11:44 AM, ID: 15382819Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/29/05 11:46 AM, ID: 15382830Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/29/05 11:47 AM, ID: 15382835Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C# Programming Language
Tags: datagrid, update
Sign Up Now!
Solution Provided By: dstanley9
Participating Experts: 1
Solution Grade: A
 
[+][-]11/29/05 11:52 AM, ID: 15382878Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81