title: updating sql server database using asp.net c#
body: <p>im having issues updating my database from a webform. I use a series of textboxes and dropdownlists which are populated by the datasource but for some reason i cant update them. </p>
  
  <p>Basically the primary key of a row is passed into the next page where the textboxes,drop down lists are populated with the data from that row.</p>
  
  <p>Here is what i have tried so far</p>
  
  <pre><code>    //Update the record with new information entered into controls
      protected void UpdateBut_Click(object sender, EventArgs e)
      {
  
          using (SqlConnection conn = new SqlConnection("Data Source=stephenp\\sqlexpress;Initial Catalog=Asset management System DB;Integrated Security=True"))
          {
              string sql = "UPDATE Peripherals SET PeripheralType=@PeripheralType, Model=@Model, PeripheralSerialNumber=@SerialNum, " +
                  "Company = @Company, Department=@Department, Status=@Status, WarrantyExpirationDate=@Warranty, PeripheralCapexNumber=@CapexNum, " +
                  "IPAddress=@IPAddress, LastModifiedDate = @LastMD, LastModifiedBy=@LastMB WHERE (PeripheralTagNumber = @PeripheralTagNumber)";
  
  
            //try
             //{
              using (SqlCommand cmd = new SqlCommand(sql, conn))
              {
                  cmd.Parameters.AddWithValue("@PeripheralType", TypeDDL.Text.Trim());
                  cmd.Parameters.AddWithValue("@Model", ModelTB.Text.Trim());
                  cmd.Parameters.AddWithValue("@SerialNum", SerialNumTB.Text.Trim());
                  cmd.Parameters.AddWithValue("@Company", CompanyDDL.Text.Trim());
                  cmd.Parameters.AddWithValue("@Department", DepartmentDDL.Text.Trim());
                  cmd.Parameters.AddWithValue("@Status", StatusDDL.Text.Trim());
                  cmd.Parameters.AddWithValue("@Warranty", DateTime.Parse(WarrantyTB.Text.Trim()).ToShortDateString());
                  cmd.Parameters.AddWithValue("@CapexNum", CapexNumTB.Text.Trim());
                  cmd.Parameters.AddWithValue("@IPAddress", IPAddressTB.Text.Trim());
                  cmd.Parameters.AddWithValue("@LastMD", DateTime.Now.Date.ToShortDateString());
                  cmd.Parameters.AddWithValue("@LastMB", Session["username"].ToString());
                  cmd.Parameters.AddWithValue("@PeripheralTagNumber", ID);
  
                  conn.Open();
                  cmd.ExecuteNonQuery();
                  conn.Close();
               }
             //}
              //catch (SqlException ex) { }
          }
  
          this.getData();
      }
  </code></pre>
  
  <p>thanks</p>