|
private void button4_Click(object sender, EventArgs e)
{
mycon.con.Close();
mycon.adp = new SqlDataAdapter("delete from Inquiry_management where Inquiry_ID='" +listBox1.SelectedIndex + "'", mycon.con);
mycon.adp.Fill(ds, "Inquiry_management");
mycon.con.Open();
mycon.con.Close();
listBox1.Update();
MessageBox.Show("Row Deleted");
}
|
|
|
|
|
There is no need to data Adapter , see this :
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("YOUR CONNECTION STRING ");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "delete from Inquiry_management where Inquiry_ID='" +listBox1.SelectedIndex + "'";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
|
|
|
|
|
it doesn't work because i am using the class method;
this is my class coding.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
///
/// Summary description for mycon
///
namespace WindowsFormsApplication1
{
class mycon
{
public static int x = 0;
public static SqlConnection con=new SqlConnection("Data Source=DRONAVAT-PC\\SQLEXPRESS;Initial Catalog=InventoryControl;Integrated Security=True");
public static SqlCommand cmd;
public static SqlDataReader dr;
public static SqlCommandBuilder cd;
public static SqlDataAdapter adp;
public static void enable()
{
}
public static void disable()
{
}
}
}
|
|
|
|