Hey every one i need some help please! I am trying to save a Database through c# but cant seem to crack it. I read a few threads but every one explains how to save an existing DB. In my program I am creating a new DB in c# then i want to save it. All the code works except the save. My program is totally useless without a save button. If someone can help please. Here's my 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;

namespace WindowsFormsApplication1
{
    public partial class New_Client : Form
    {
        public New_Client()
        {
            InitializeComponent();
        }

            //create variable holding count
            int count = 0;

            //create datatable
            DataTable kliente;

        private DataTable MaakKlientTabel()
        {
            // Create new table 'Kliente';
            DataTable kliente = new DataTable("Kliente");

            // Add column objects in the table.
            DataColumn Naam = new DataColumn();
            Naam.DataType = System.Type.GetType("System.String");
            Naam.ColumnName = "Name";
            Naam.DefaultValue = "";
            kliente.Columns.Add(Naam);

            DataColumn Van = new DataColumn();
            Van.DataType = System.Type.GetType("System.String");
            Van.ColumnName = "Surname";
            Van.DefaultValue = "";
            kliente.Columns.Add(Van);

            DataColumn ID = new DataColumn();
            ID.DataType = System.Type.GetType("System.String");
            ID.ColumnName = "ID";
            kliente.Columns.Add(ID);

            DataColumn Adres = new DataColumn();
            Adres.DataType = System.Type.GetType("System.String");
            Adres.ColumnName = "Adress";
            kliente.Columns.Add(Adres);

            DataColumn Kontak = new DataColumn();
            Kontak.DataType = System.Type.GetType("System.String");
            Kontak.ColumnName = "Contact";
            kliente.Columns.Add(Kontak);

            DataColumn Provinsie = new DataColumn();
            Provinsie.DataType = System.Type.GetType("System.String");
            Provinsie.ColumnName = "Province";
            kliente.Columns.Add(Provinsie);

            DataColumn CD = new DataColumn();
            CD.DataType = System.Type.GetType("System.Int32");
            CD.ColumnName = "CardNumber";
            kliente.Columns.Add(CD);

            DataColumn MOC = new DataColumn();
            MOC.DataType = System.Type.GetType("System.Decimal");
            MOC.ColumnName = "MoneyOnCard";
            kliente.Columns.Add(MOC);

            // Make an array of DataColumn objects.
            DataColumn[] PK = new DataColumn[1];
            PK[0] = ID;
            kliente.PrimaryKey = PK;

            // Return new table.
            return kliente;

        }


        private void MaakNuweDataRy()
        {



            // when a table is created make use of NewRow to create a new row
            DataRow ry;
            ry = kliente.NewRow();

            // Add die nuwe ry by die kolleksie
            ry["Name"] = textBox1.Text;
            ry["Surname"] = textBox2.Text;
            ry["ID"] = textBox3.Text;
            ry["Adress"] = textBox4.Text;
            ry["Contact"] = textBox8.Text;
            ry["Province"] = comboBox2.SelectedItem;
            ry["CardNumber"] = textBox5.Text;
            ry["MoneyOnCard"] = textBox6.Text;
            kliente.Rows.Add(ry);

            foreach (DataColumn kolom in kliente.Columns)
            Console.WriteLine(kolom.ColumnName);
            dataGridView1.DataSource = kliente;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.klientTableAdapter.Fill(this.klientDataSet.Klient);

                //create variables
            /*string IDSub = textBox3.Text.Substring(0, 6);

            string DOBDay = textBox7.Text.Substring(0, 2);
            string DOBMonth = textBox7.Text.Substring(3, 2);
            string DOBYear = textBox7.Text.Substring(8, 2);

            string DOBSub = (DOBYear + DOBMonth + DOBDay);

            int gesl = Convert.ToInt32(textBox3.Text.Substring(6, 1));

            bool IDtoets = false;*/
            bool NaamToets = false;
            bool VanToets = false;
            bool AdresToets = false;
            bool KontakToets = false;
            bool RasToets = false;
            bool ProvinsieToets = false;
            bool KaartNomToets = false;
            bool KaartGeldToets = false;

                //Test the input
            /* if (IDSub == DOBSub && textBox3.TextLength == 13 && ((gesl < 5 && comboBox3.SelectedIndex == 1) || (gesl >= 5 && comboBox3.SelectedIndex == 0)))
                {

                IDtoets = true;

                }
               else
                {

                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with DOB, ID and Sex combinatition." + "\n" + "Make sure everything is typed in correctly");
                textBox3.Clear();
                textBox7.Clear();
                comboBox3.SelectedIndex = -1;
                IDtoets = false;

                } */

                if (textBox1.Text == "")
                {

                NaamToets = false;
                textBox1.Clear();
                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with Name." + "\n" + "Make sure a name is typed in.");

                }
                else 
                {

                NaamToets = true;

                }

                if (textBox2.Text != "")
                {

                VanToets = true;

                }
                else
                {

                VanToets = false;
                textBox2.Clear();
                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with Surname." + "\n" + "Make sure a Surname is typed in.");

                }

                if (textBox4.Text != "")
                {

                AdresToets = true;

                }
                else
                {

                AdresToets = false;
                textBox4.Clear();
                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with Adress." + "\n" + "Make sure a Adress is typed in.");

                }

                if (textBox8.Text != "")
                {

                KontakToets = true;

                }
                else
                {

                KontakToets = false;
                textBox8.Clear();
                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with Contact." + "\n" + "Make sure a Contact is typed in.");

                }

                if (comboBox1.SelectedIndex != -1)
                {

                RasToets = true;

                }
                else
                {

                RasToets = false;
                comboBox1.SelectedIndex = -1;
                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with Race." + "\n" + "Make sure a Race is selected.");

                }

                if (comboBox2.SelectedIndex != -1)
                {

                ProvinsieToets = true;

                }
                else
                {

                ProvinsieToets = false;
                comboBox2.SelectedIndex = -1;
                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with Province." + "\n" + "Make sure a Province is selected.");

                }

                if (textBox6.Text != "")
                {

                KaartGeldToets = true;

                }
                else
                {

                KaartGeldToets = false;
                textBox6.Clear();
                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with Money on Card" + "\n" + "Make sure Money on Card is typed in.");

                }

                if (textBox5.Text != "")
                {

                KaartNomToets = true;

                }
                else
                {

                KaartNomToets = false;
                textBox5.Clear();
                MessageBox.Show("Client not added." + "\n" + "\n" + "Problem with Card Number" + "\n" + "Make sure a Card Number is typed in.");

                }

                    //Tests if all tests where true
                if (/*(IDtoets == true) && */(NaamToets == true) && (VanToets == true) && (AdresToets == true) && (KontakToets == true) && (RasToets == true) && (ProvinsieToets == true) && (KaartGeldToets == true) && (KaartNomToets == true))
                {

                    //Call method MaakNuweDataRy to add a new row
                 MaakNuweDataRy();

                    //Update table
                 this.Validate();  
                 this.klientBindingSource.EndEdit();
                 this.tableAdapterManager.UpdateAll(this.klientDataSet);

                    //Show message a new client has been addes
                 MessageBox.Show("Client Added");

                    //close active form and open previous
                 //New_Client.ActiveForm.Close();
                 // Form2 kind = new Form2();
                 // kind.Show();

                }
            }

        private void New_Client_Load(object sender, EventArgs e)
        {

            // Make use of MaakKlientTabel function to create a new table
            kliente = MaakKlientTabel();

            // TODO: This line of code loads data into the 'klientDataSet.Klient' table. You can move, or remove it, as needed.
            this.klientTableAdapter.Fill(this.klientDataSet.Klient);

        }

        private void button2_Click(object sender, EventArgs e)
        {

                //close active form and open previous
            ActiveForm.Close();
            Form2 kind = new Form2();
            kind.Show();

        }

        private void klientBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {

            this.Validate();
            this.klientBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.klientDataSet);

        }


    }
}

Edited 3 Years Ago by Dani: Formatting fixed

when I want to upload it it says

invalid file

sorry.

The code above is all of the coding in that part of my project.

Can you try using something like dropbox to upload with, problem is not being able to see your windows forms properties.

This article has been dead for over six months. Start a new discussion instead.