Input Toggle button checkbox value insert into sql server
Loading
Input Toggle button checkbox value insert into sql server
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rathrola Prem KumarRank #307 · 8.2K reputationPosted Aug 24, 2023, 8:37 AM EDT
Can elaborate your issue with code snippet please?
Prem Sudhan49 reputationPosted Aug 31, 2023, 4:53 AM EDT
i need check box toggle click event only insert the data into sql server
Mohammad HussainRank #513 · 4.8K reputationPosted Aug 24, 2023, 1:33 PM EDT
Insert function insertValue() { var toggleButton = document.getElementById("toggleButton"); var isChecked = toggleButton.checked; // Call a function to send the value to the server sendDataToServer(isChecked); } function sendDataToServer(value) { // Send the value to the server using AJAX // Example using fetch API fetch("/InsertToggleValue", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ value: value }) }) .then(response => response.json()) .then(data => { // Handle response from server if needed }) .catch(error => { console.error("Error:", error); }); }[HttpPost] public IHttpActionResult InsertToggleValue([FromBody] ToggleValueModel model) { if (model == null) { return BadRequest("Invalid data."); } // Insert the value into the SQL Server database using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string query = "INSERT INTO YourTable (ToggleValueColumn) VALUES (@Value)"; using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@Value", model.Value); command.ExecuteNonQuery(); } } return Ok("Value inserted successfully."); } public class ToggleValueModel { public bool Value { get; set; } }