Advertisement
Sabab

GateWay

Oct 20th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1.   public void UpdateCheckboxValueOfIndexPage(string userName,string checkboxValue, string checkedValue)
  2.         {
  3.            
  4.             SqlConnection connection=new SqlConnection(connectionString);
  5.  
  6.             try
  7.             {
  8.                 string updateQuery = "UPDATE UserChoiceTable SET  Checked=@Checked WHERE UserName=@UserName AND CheckBoxValue=@CheckBoxValue";
  9.  
  10.  
  11.                 SqlCommand command = new SqlCommand(updateQuery, connection);
  12.  
  13.                 command.Parameters.Clear();
  14.  
  15.                 command.Parameters.Add("UserName", SqlDbType.VarChar);
  16.                 command.Parameters["UserName"].Value = userName;
  17.  
  18.                 command.Parameters.Add("CheckBoxValue", SqlDbType.VarChar);
  19.                 command.Parameters["CheckBoxValue"].Value = checkboxValue;
  20.  
  21.                 command.Parameters.Add("Checked", SqlDbType.VarChar);
  22.                 command.Parameters["Checked"].Value = checkedValue;
  23.  
  24.  
  25.  
  26.  
  27.                 connection.Open();
  28.                 int rowAffected = command.ExecuteNonQuery();
  29.                 connection.Close();
  30.  
  31.             }
  32.             catch (Exception ex)
  33.             {
  34.                
  35.             }
  36.  
  37.  
  38.         }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.         public string CheckBoxChecked(string userName, string checkBoxValue)
  48.         {
  49.  
  50.             string Ischecked = null;
  51.  
  52.             SqlConnection connection = new SqlConnection(connectionString);
  53.             try
  54.             {
  55.                 string query = "SELECT * FROM UserChoiceTable WHERE UserName=@UserName AND CheckBoxValue=@CheckBoxValue";
  56.  
  57.                 SqlCommand command = new SqlCommand(query, connection);
  58.  
  59.                 command.Parameters.Clear();
  60.                 command.Parameters.Add("UserName", SqlDbType.VarChar);
  61.                 command.Parameters["UserName"].Value = userName;
  62.                 command.Parameters.Add("CheckBoxValue", SqlDbType.VarChar);
  63.                 command.Parameters["CheckBoxValue"].Value = checkBoxValue;
  64.  
  65.  
  66.                 connection.Open();
  67.  
  68.  
  69.                 SqlDataReader reader = command.ExecuteReader();
  70.  
  71.                 if (reader.Read())
  72.                 {
  73.                     Ischecked = reader["Checked"].ToString();
  74.  
  75.  
  76.                 }
  77.  
  78.  
  79.                 return Ischecked;
  80.             }
  81.             catch (Exception ex)
  82.             {
  83.  
  84.                 return Ischecked = null;
  85.             }
  86.  
  87.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement