Advertisement

12.01.2008 at 01:19PM PST, ID: 23948072 | Points: 500
[x]
Attachment Details

List box add,edit and delete event

Tags:

c#, Windowsform control(List Box)

I have 3 buttons add,edit,delete beneath the list box.If a user clicks on add then it should add a new item to the existing list box ,since it is used query through database.When clicked on add it should insert a record into the table and show on the list box.
Similarly edit and delete should work.Edit should update the database and delete should delete the record from database.
Here by I am attaching my sample code.

My code is incomplete and I am sure its wrong.I want some one to correct the code.

Thanks!!!!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
private void AddButton_Click(object sender, EventArgs e)
        {
            {
                ApplicationsListBox.SelectedIndex = -1;
               if (ApplicationsListBox.SelectedItem == null)
                  {
                      //string app = ApplicationsListBox.
                      efpData.InsertApplications();
                   //MessageBox.Show("Select a skill to add"); 
                     // ApplicationsListBox.Items.Add();
                         
 
                  }
               else
               {
                   int found;
                   found = ApplicationsListBox.FindStringExact(ApplicationsListBox.SelectedItem.ToString());
                   if (found == 0)
                   {
                       ApplicationsListBox.Items.Add(ApplicationsListBox.SelectedItem); }
                   else { MessageBox.Show("Application already exists"); }
               }
            }
        }ApplicationsListBox.FindStringExact(ApplicationsListBox.SelectedItem.ToString());
                   if (found == 0)
                   {
                       ApplicationsListBox.Items.Add(ApplicationsListBox.SelectedItem); }
                   else { MessageBox.Show("Application already exists"); }
               }
            }
        }
 
 
EFPDATA.CS
 
 
    public List<string> InsertApplications(string app)
    {
 
        List<string> insertApp = new List<string>();
 
        Database _db;
       _db = DatabaseFactory.CreateDatabase("InformixConnection");
       
        string query = "INSERT INTO [efpapplication] (app)VALUES (@app);";
 
 
        using (DbCommand appCommand = _db.GetSqlStringCommand(query))
        {
           
            appCommand.Parameters.Add(new OleDbParameter("@app",app));
            appCommand.CommandType = CommandType.Text;
 
            using (IDataReader rdr = _db.ExecuteReader(appCommand))
            {
                while (rdr.Read())
                {
 
                    insertApp.Add(rdr["app"].ToString());
 
                }
            }
        }
 
        return insertApp;
 
    }
 
Expert Comment by jandromeda:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by onebite2:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by jandromeda:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-46 - Hierarchy / EE_QW_Related_20080208