private void Obrisi(string Symbol)
{
SqlConnection cnn = new SqlConnection(Properties.Settings.Default.connection);
cnn.Open();
SqlCommand cm = new SqlCommand();
cm.Connection = cnn;
cm.CommandText = "DELETE FROM dQuotes WHERE tSymbol ='"+ Symbol+"'";
cm.Parameters.AddWithValue("@Class_Name", Symbol);
try
{
cm.ExecuteNonQuery();
MessageBox.Show("Deleted");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cnn.Close();
listView1.Items.Clear();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems == null)
{
MessageBox.Show("Please select Class to Delete");
return;
}
string Symbol = (listView1.SelectedItems).ToString();
Obrisi(Symbol);
}
message comes deleted but still symbol fom database have not deleted. my database name is dQuotes and the column name into database is tSymbol.plz give me complete code or make a short project on that .
try
{
foreach (int i in listView1.SelectedIndices)
{
string lvSymbol= listView1.Items[i].Text; listView1.Items.Remove(listView1.Items[i]);
using (var cnn = new SqlConnection(Properties.Settings.Default.connection))
using (var cmd = cnn.CreateCommand())
{
cnn.Open();
cmd.CommandText = "DELETE FROM dQuotes WHERE tSymbol= @tSymbol";
cmd.Parameters.AddWithValue("@tSymbol", lvSymbol);
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
got error still delete from listview but not from database my database column name is tSymbol so plz give me complete code for that and also add search by keyword in listview
Notice also that because the connection is wrapped in a using block you don't need to Close it in a finally statement. The Dispose method will automatically call the .Close method which will return the connection to the ADO.NET connection pool so that it can be reused.
chkBox.setOnClickListener(newnewOnClickListener(){@Overridepublicvoid onClick(View v){// TODO Auto-generated method stub CheckBox cb =(CheckBox)v;if(cb.isChecked()==true){String getStrinValue = cb.getTExt().toString();// here you will get the value of selected CheckBox// And now you have to perform your deletion operation as usual. }}
Vivek JoyPosted Sep 11, 2015, 9:21 AM
Baimey RajeshPosted Sep 10, 2015, 3:00 AM
Baimey RajeshPosted Sep 10, 2015, 2:05 AM
Baimey RajeshPosted Sep 10, 2015, 1:53 AM
VedantPosted Sep 10, 2015, 1:50 AM
Baimey RajeshPosted Sep 10, 2015, 1:45 AM
VedantPosted Sep 10, 2015, 1:42 AM
VedantPosted Sep 10, 2015, 1:42 AM
VedantPosted Sep 10, 2015, 1:42 AM
VedantPosted Sep 9, 2015, 12:29 PM
Baimey RajeshPosted Sep 9, 2015, 8:38 AM
Baimey RajeshPosted Sep 9, 2015, 8:33 AM
VedantPosted Sep 9, 2015, 8:30 AM
Baimey RajeshPosted Sep 9, 2015, 8:25 AM
VedantPosted Sep 9, 2015, 8:23 AM
VedantPosted Sep 9, 2015, 7:47 AM
Baimey RajeshPosted Sep 9, 2015, 7:29 AM
Baimey RajeshPosted Sep 9, 2015, 7:14 AM
VedantPosted Sep 9, 2015, 7:00 AM
Baimey RajeshPosted Sep 9, 2015, 5:08 AM
finallystatement. The Dispose method will automatically call the .Close method which will return the connection to the ADO.NET connection pool so that it can be reused.Baimey RajeshPosted Sep 9, 2015, 5:06 AM
VedantPosted Sep 9, 2015, 4:09 AM
Baimey RajeshPosted Sep 8, 2015, 9:16 AM
Harshad PansuriyaPosted Sep 8, 2015, 8:54 AM
Baimey RajeshPosted Sep 8, 2015, 8:48 AM
Arun KumarPosted Sep 8, 2015, 8:43 AM
Harshad PansuriyaPosted Sep 8, 2015, 8:41 AM
Here's the general path you'll have to follow.
ArrayListthat is populating yourListView.notifyDataSetChanged()on theAdapterthat is being used for theListViewVedantPosted Sep 8, 2015, 8:35 AM
Baimey RajeshPosted Sep 8, 2015, 8:32 AM
{do u want to remove from the database on each item click. or do u have a separate button to delete?