Thread: C# and SQL

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    5

    Question C# and SQL

    Hello,

    I am doing a big project for personal goal to get more familiar with C# and SQL, ok the project is a help desk simple and small, i have 3 forms, the first asks you to either go into form 2 which is the profile to have the user enter customer profile information (first name, last name etc) and in form 2 there are 4 buttons, add (add new customer profile), Delete (delete customer profile that is selected), Update( select the customer from the listbox and in the text field change anything and have it take changes fast in SQL database), and of course close,

    MY problem i have the code below, for the add button, when i click on it, it will add a new blank field in the list box which after i click add, i have to click on the list box for a drop down of a blank line and select it to add, is there a way to just click add and it clears all fields for the add new customer profile?

    The Delete button is also a problem, when i select a profile to delete, it delete the entire thing!! not good, and what is weird is it has the same problem as the update, any changes made using the C# to interact with SQL DB, once i close out the program and re-open it, the changes made are gone, it goes back to older.

    Update problem is when i make a change click update, it looks like it works because i go out of form 2 back to form 1, click on form2 again and it took the change, but closing out the program entering it back it will go back to old settings, whats the deal? i have ALL the code listed below PLEASE HELP!! MSDN or other forums no help....

    This is form 2 customer profile:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox6_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void Form2_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the 'insighthdDataSet.enterinfo' table. You can move, or remove it, as needed.
                this.enterinfoTableAdapter.Fill(this.insighthdDataSet.enterinfo);
                enterinfoTableAdapter.Fill(insighthdDataSet.enterinfo);
    
                        
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
             insighthdDataSetBindingSource.EndEdit();
             enterinfoTableAdapter.Update(insighthdDataSet.enterinfo);
             MessageBox.Show("Update Complete");
            }
    
            private void bindingSource1_CurrentChanged(object sender, EventArgs e)
            {
    
            }
    
            private void label24_Click(object sender, EventArgs e)
            {
    
            }
    
            private void primarycontactLabel_Click(object sender, EventArgs e)
            {
    
            }
    
            private void enterinfoBindingNavigatorSaveItem_Click(object sender, EventArgs e)
            {
                
            }
    
            private void enterinfoBindingNavigator_Refre........ems(object sender, EventArgs e)
            {
    
            }
    
            private void fillByToolStripButton_Click(object sender, EventArgs e)
            {
                
            }
    
            private void customerticketTextBox_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
    
            }
    
            private void enterinfoBindingNavigatorSaveItem_Click_1(object sender, EventArgs e)
            {
                
            }
    
            private void integratorcompanyTextBox_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void enterinfoBindingNavigatorSaveItem_Click_2(object sender, EventArgs e)
            {
                this.Validate();
                this.enterinfoBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.insighthdDataSet);
    
            }
    
            private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
            {
    
            }
    
            private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
            {
    
            }
    
            private void toolStripButton1_Click(object sender, EventArgs e)
            {
               
            }
    
            private void fillByToolStripButton_Click_1(object sender, EventArgs e)
            {
                try
                {
                    this.enterinfoTableAdapter.FillBy(this.insighthdDataSet.enterinfo);
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
    
            }
    
            private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e)
            {
    
            }
    
            private void customerlocationTextBox_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void enterinfoBindingSource_CurrentChanged(object sender, EventArgs e)
            {
    
            }
    
            private void button3_Click_1(object sender, EventArgs e)
            {
            }
    
            private void button3_Click_2(object sender, EventArgs e)
            {
                insighthdDataSet.enterinfoRow row =
        insighthdDataSet.enterinfo.NewenterinfoRow();
                insighthdDataSet.enterinfo.Rows.Add(row);
    
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                insighthdDataSet.enterinfo.Clear();
               
            }
        }
    }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You should name your stuff better. "button3" and "label24" doesn't really tell what they are.

    As for clearing in Add New, can't you just clear all textfields (or whatever you use), like: textfield_username.Text = "" and so on?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    5

    Question

    Yes sorry for not labeling the buttons, button 2 is update, button 3 is add, button 4 is delete, i dont know if that would work, can you give me the code? ask you can see above the code delete the entire table, can you give an example atleast or resource?

Popular pages Recent additions subscribe to a feed