Click here to Skip to main content
15,790,243 members
Home / Discussions / C#
   

C#

 
GeneralRe: mysql delete code error Pin
Dave Kreskowiak19-Mar-22 18:54
mveDave Kreskowiak19-Mar-22 18:54 
GeneralRe: mysql delete code error Pin
N Mohamed rafi19-Mar-22 19:01
N Mohamed rafi19-Mar-22 19:01 
GeneralRe: mysql delete code error Pin
Dave Kreskowiak19-Mar-22 19:39
mveDave Kreskowiak19-Mar-22 19:39 
GeneralRe: mysql delete code error Pin
N Mohamed rafi19-Mar-22 20:48
N Mohamed rafi19-Mar-22 20:48 
AnswerRe: mysql delete code error Pin
OriginalGriff19-Mar-22 22:04
mvaOriginalGriff19-Mar-22 22:04 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 0:05
N Mohamed rafi20-Mar-22 0:05 
GeneralRe: mysql delete code error Pin
OriginalGriff20-Mar-22 0:35
mvaOriginalGriff20-Mar-22 0:35 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 1:02
N Mohamed rafi20-Mar-22 1:02 
Sir, i have heard and tried what you said, the below coding is here; if i run coding it shows record deleted successfully but still the record not deleting from database

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;

private void DisplayData()
{
string connectionString;
MySqlConnection cnn;
connectionString = @"Data Source=localhost;Initial Catalog=testDB;User ID=root;Password=mysql";
cnn = new MySqlConnection(connectionString);
DataTable dt = new DataTable();
adapt = new MySqlDataAdapter("select * from employee", cnn);
adapt.Fill(dt);
dataGridView1.DataSource = dt;
cnn.Open();
cnn.Close();
}
private void ClearData()
{
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
ID = 0;
}
private void button9_Click(object sender, EventArgs e)
{
if (textBox6.Text!= "" && textBox7.Text != "" && textBox8.Text != "")
{
string connectionString;
MySqlConnection cnn;
connectionString = @"Data Source=localhost;Initial Catalog=testDB;User ID=root;Password=mysql";
cnn = new MySqlConnection(connectionString);
string id = textBox6.Text;
string name = textBox7.Text;
string salary = textBox8.Text;
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
string query = "DELETE FROM employee WHERE employee_id=@employee_id AND employee_name=@employee_name AND employee_salary-@employee_salary";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("@employee_id", id);
cmd.Parameters.AddWithValue("@employee_name", name);
cmd.Parameters.AddWithValue("@employee_salary", salary);
cmd.Connection = cnn;
cnn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Record Deleted Successfully");
cnn.Close();
DisplayData();
ClearData();
}
}
else
{
MessageBox.Show("Please Select Record to Delete");
}
}
GeneralRe: mysql delete code error Pin
OriginalGriff20-Mar-22 1:37
mvaOriginalGriff20-Mar-22 1:37 
GeneralRe: mysql delete code error Pin
Richard MacCutchan20-Mar-22 3:13
mveRichard MacCutchan20-Mar-22 3:13 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 3:21
N Mohamed rafi20-Mar-22 3:21 
GeneralRe: mysql delete code error Pin
Richard MacCutchan20-Mar-22 3:25
mveRichard MacCutchan20-Mar-22 3:25 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 2:58
N Mohamed rafi20-Mar-22 2:58 
GeneralRe: mysql delete code error Pin
OriginalGriff20-Mar-22 3:33
mvaOriginalGriff20-Mar-22 3:33 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 3:46
N Mohamed rafi20-Mar-22 3:46 
GeneralRe: mysql delete code error Pin
OriginalGriff20-Mar-22 4:26
mvaOriginalGriff20-Mar-22 4:26 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 4:46
N Mohamed rafi20-Mar-22 4:46 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 3:47
N Mohamed rafi20-Mar-22 3:47 
GeneralRe: mysql delete code error Pin
N Mohamed rafi20-Mar-22 4:09
N Mohamed rafi20-Mar-22 4:09 
GeneralRe: mysql delete code error Pin
Dave Kreskowiak20-Mar-22 5:51
mveDave Kreskowiak20-Mar-22 5:51 
GeneralConnection string Error VS to Mysql Pin
N Mohamed rafi18-Mar-22 21:32
N Mohamed rafi18-Mar-22 21:32 
GeneralRe: Connection string Error VS to Mysql Pin
OriginalGriff18-Mar-22 22:04
mvaOriginalGriff18-Mar-22 22:04 
GeneralRe: Connection string Error VS to Mysql Pin
N Mohamed rafi18-Mar-22 22:08
N Mohamed rafi18-Mar-22 22:08 
GeneralRe: Connection string Error VS to Mysql Pin
OriginalGriff18-Mar-22 22:17
mvaOriginalGriff18-Mar-22 22:17 
GeneralRe: Connection string Error VS to Mysql Pin
N Mohamed rafi18-Mar-22 22:27
N Mohamed rafi18-Mar-22 22:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.