9 Replies - 1353 Views - Last Post: 13 December 2012 - 05:38 PM Rate Topic: -----

#1 JG7000  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-December 12

Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 01:01 PM

The cose workes perfectly, but just one glich, I cant seem to figur out how to implement a function ot method or sql statement to delete the selected item ( which is the name of the member, while the selected item is displayed in combobox,by clicking the delete button it should delete the whole record about the member.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication2
{
    public partial class frmDeleteMember : Form
    {
        public frmDeleteMember() 
        {
            InitializeComponent();
        }

        SqlDataAdapter da;
        DataSet ds = new DataSet();

        private void frmDeleteMember_Load(object sender, EventArgs e)
        {
            String conStr = "Data Source=My-PC\\SQLEXPRESS;Initial Catalog=TESTSUB;Integrated Security=True";
            SqlConnection con = new SqlConnection(conStr);
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT * FROM members";
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "members");
            this.cmbDeleteMember.SelectedIndexChanged -= new System.EventHandler(this.cmbDeleteMember_SelectedIndexChanged);
            cmbDeleteMember.DataSource = ds.Tables["members"];
            cmbDeleteMember.DisplayMember = "FullName";
            cmbDeleteMember.ValueMember = "ID";
            this.cmbDeleteMember.SelectedIndexChanged += new System.EventHandler(this.cmbDeleteMember_SelectedIndexChanged);
        }
 
        private void cmbDeleteMember_SelectedIndexChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Members Primary Key is \"" + cmbDeleteMember.SelectedValue + "\"");
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            // Idea needed for deleteing the selected info "row" about member by clicking this button
        }
    }
}

This post has been edited by tlhIn`toq: 13 December 2012 - 05:43 PM
Reason for edit:: highlight the text and just click the 'code' button in the text editor


Is This A Good Question/Topic? 0
  • +

Replies To: Idea for Deleteing the selected item [resolved]

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,661
  • Joined: 02-June 10

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 01:09 PM

View PostJG7000, on 13 December 2012 - 02:01 PM, said:

The cose workes perfectly, but just one glich, I cant seem to figur out how to implement a function ot method or sql statement to delete the selected item ( which is the name of the member, while the selected item is displayed in combobox,by clicking the delete button it should delete the whole record about the member.


Is there something wrong with your keyboard? You have numerous missing or swapped letters in your post. If we can't figure out what you are saying/asking it makes it hard to help you.

"I can't think of a way to do this" isn't exactly something we can help with. Your ability to think is outside of our control.

What part don't you understand? How to send a delete command to a database... How to react to a button being clicked... how to determine what is selected in a combobox...

[*]Q:... how to do x,y,z with a database {probably for the first time}...
A: Read this tutorial
Entire section of tutorials
Parameterizing Your SQL Queries: The RIGHT Way To Query A Database.
Using SqlDependency to monitor SQL database changes
Was This Post Helpful? 0
  • +
  • -

#3 JG7000  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-December 12

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 01:36 PM

There is nothing wrong with my keyboard, just mistyped while writing down the question down, I am very surprised by your attitude how you treat people I have asked a simple question if you don’t understand it not my problem !!! Everybody is not born a professor of programming,
Had I been that big geek I should have done it myself!!! I have asked that I have used a code which connects with a database and displays the Full name of members and when selected pops up a box by showing the ID and that’s fine. What I have a asked is that is, a logical way to maybe use an sql statement to just delete the member from the database. And you are writing me links for tutorials , which you think that I might have missed and have lots of time to spend hour reading them.
Peace of advice to you I don’t care if you Professor or Guru of Programming, you can answer people like that , like telling someone off, you are not the only forum on the internet.

This post has been edited by tlhIn`toq: 13 December 2012 - 04:57 PM
Reason for edit:: Don't quote the ENTIRE previous post. We all see and doing so just makes the thread a mile long.

Was This Post Helpful? -1
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8940
  • View blog
  • Posts: 33,527
  • Joined: 12-June 08

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 01:46 PM

It's the same steps (more or less) of getting data.

  • Create connection object
  • Open connection object
  • Create command object
  • Set the command text to a typical delete.
    DELETE from <table name> 
      WHERE <condition>
    

  • Add parameters for the where condition
  • execute the command object


We have plenty of tutorials outlining all of this.
Example:

http://www.dreaminco...basics-in-c%23/
http://www.dreaminco...iew-using-c%23/
http://www.dreaminco...asics-in-vbnet/
http://www.dreaminco...imple-database/


Quote

Peace of advice to you I don’t care if you Professor or Guru of Programming, you can answer people like that , like telling someone off, you are not the only forum on the internet.

Simmer down there champ. Someone was just asking a question and trying to get clarification from you.

A piece of advice back at'cha - some days you will encounter people that do not communicate in a way that you personally enjoy. It does not make these people any less right or their information less accurate. If you cannot get past a blunt conversation tone then you will have a long hard road a head of you. Learn to see the information outside of your percieved tone and you'll go far.

This post has been edited by modi123_1: 13 December 2012 - 01:56 PM

Was This Post Helpful? 3
  • +
  • -

#5 JG7000  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-December 12

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 02:30 PM

Firstly thank you ever so much for your reply and suggestion, I find a friendly and kind vibe in your tone. What I have learned from my upbringing that respect people irrespective of one’s intelligence or weaknesses. The previous reply might be in a good intention but the tone is was very disrespectful, that’s how I feel, of course I know everybody don’t have same attitude but one can’t lay down and let everyone walk over you.
Anyways thanks I will try your approach !

This post has been edited by tlhIn`toq: 13 December 2012 - 04:57 PM
Reason for edit:: Don't quote the ENTIRE previous post. We all see and doing so just makes the thread a mile long.

Was This Post Helpful? 0
  • +
  • -

#6 JG7000  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-December 12

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 02:47 PM

Here is my approach for deleting
private void btnDel_Click(object sender, EventArgs e)
        {
            String conStr = "Data Source=JG-PC\\SQLEXPRESS;Initial Catalog=TESTSUB;Integrated Security=True";
            SqlConnection con = new SqlConnection(conStr);
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "DELETE * FROM members WHERE '" + cmbDeleteMember.SelectedValue + "'";
            da = new SqlDataAdapter(cmd);
            con.Open();
            cmd.ExecuteNonQuery();

        }

still getting en error
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8940
  • View blog
  • Posts: 33,527
  • Joined: 12-June 08

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 02:49 PM

There is no "DELETE *" it's just DELETE.

Quote

WHERE '" + cmbDeleteMember.SelectedValue + "'";

You are missing the column name needed for a comparison.
Was This Post Helpful? 1
  • +
  • -

#8 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 02:50 PM

SQL delete:

DELETE FROM table_name
WHERE some_column=some_value


Was This Post Helpful? 2
  • +
  • -

#9 JG7000  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-December 12

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 03:00 PM

Thanks Guys you are super , got it working ..many thanks to both of ya !!!
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,661
  • Joined: 02-June 10

Re: Idea for Deleteing the selected item [resolved]

Posted 13 December 2012 - 05:38 PM

Completely non-code reply to JG7000 to a completely non-code comment.
Those not interested don't have to open the spoiler tag

Spoiler


I truly hope you enjoy your use of the system. I hope you get some good advice from the group. I hope that someday you progress enough to give some advice to the generation coming up after you. Best of luck in all your future endeavors both on and off the keyboard.
Was This Post Helpful? 4
  • +
  • -

Page 1 of 1