[C#] SQL i problem z connection string i update

0

witam
mam ksiazkowy przyklad a mimo to wciaz wywala bledy

ostatni blad ktorego nie udalo mi sie wyeliminowac to
"Dynamiczne generowanie kodu SQL dla elementu UpdateCommand nie jest obsługiwane dla elementu SelectCommand, który nie zwraca żadnych informacji o kolumnie klucza."

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 Pabo.Calendar;



namespace WindowsFormsApplication1
{
    public partial class frmCRM : Form

    {
        public frmCRM()
        {
         InitializeComponent();
        }


        System.Data.SqlClient.SqlConnection con;
        DataSet ds1;
        System.Data.SqlClient.SqlDataAdapter da;

        int MaxRows = 0;
        int inc = 0;


           

        public void frmCRM_Load(object sender, EventArgs e)
        {
            con = new System.Data.SqlClient.SqlConnection();
            ds1 = new DataSet();
            con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Database1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

            con.Open();
            string sql = "SELECT * From Kontrahenci";
            da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
            da.Fill(ds1, "Wpisy");
            NavigateRecords();
            MaxRows = ds1.Tables["Wpisy"].Rows.Count;
            
            con.Close();
          //  con.Dispose();

        }

     
        private void NavigateRecords()
        {
            DataRow dRow = ds1.Tables["Wpisy"].Rows[inc];

            textBox1.Text = dRow.ItemArray.GetValue(1).ToString();
            textBox2.Text = dRow.ItemArray.GetValue(2).ToString();
            textBox3.Text = dRow.ItemArray.GetValue(3).ToString();


        }

        private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Czy na pewno chcesz wyjść", "Wyjście", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void otwórzToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string Opened_File = "";

            openFD.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFD.Title = "Otwórz baze";
            openFD.FileName = "imie.txt";
            openFD.Filter = "TXT|*.txt|Wszystkie pliki|*.*";


            if (openFD.ShowDialog() != DialogResult.Cancel)
            {
                Opened_File = openFD.FileName;
            }
        }

        private void mnuZapisz_Click(object sender, EventArgs e)
        {
            string Saved_File = "";
            saveFD.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFD.Title = "Zapisz baze";
            saveFD.FileName = "imie.txt";
            saveFD.Filter = "TXT|*.txt|Wszystkie pliki|*.*";


            if (saveFD.ShowDialog() != DialogResult.Cancel)
            {
                Saved_File = openFD.FileName;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (inc != MaxRows - 1)
            {
                inc++;
                NavigateRecords();

            }
            else
            {
                MessageBox.Show("Nie ma wiecej rzedow");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (inc > 0)
            {
                inc--;
                NavigateRecords();
            }
            else
            {
                MessageBox.Show("Pokaz pierwszy rzad");
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (inc != MaxRows - 1)
            {
                inc = MaxRows - 1;
                NavigateRecords();

            }
        }

        private void button4_Click(object sender, EventArgs e)
        {


            if (inc != 0)
            {
                inc = 0;
                NavigateRecords();

            }
        }

        private void cmbDodaj_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();

        }

        private void cmbZapisz_Click(object sender, EventArgs e)
        {

            System.Data.SqlClient.SqlCommandBuilder cb;
            cb = new System.Data.SqlClient.SqlCommandBuilder(da);

            DataRow dRow = ds1.Tables["Wpisy"].NewRow();

            dRow[1] = textBox1.Text.ToString();
            dRow[2] = textBox2.Text.ToString();
            dRow[3] = textBox3.Text.ToString();

            ds1.Tables["Wpisy"].Rows.Add(dRow);
             ds1.AcceptChanges();

            MaxRows = MaxRows + 1;
            inc = MaxRows - 1;

                da.Update(ds1, "Wpisy");

            MessageBox.Show("Wpis dodano");
        }

        private void mnuTerminarz1_Click(object sender, EventArgs e)
        {

          Form3 frm = new Form3();
            frm.Show();
        }
 


        private void mnuAbout_Click(object sender, EventArgs e)
        {
            About frm = new About();
            frm.Show();

          
        }

        private void mnuwzornik_Click(object sender, EventArgs e)
        {

            wzorniki frm = new wzorniki();
            frm.Show();
        }

        private void cmbskasuj_Click(object sender, EventArgs e)
        {
            System.Data.SqlClient.SqlCommandBuilder cb;
            cb = new System.Data.SqlClient.SqlCommandBuilder(da);
            
            ds1.Tables["Wpisy"].Rows[inc].Delete();
            MaxRows--;
            inc = 0;
            NavigateRecords();

            da.Update(ds1, "Wpisy");

            MessageBox.Show("Skasowane");


        }

        private void cmbfind_Click(object sender, EventArgs e)
        {
            string searchFor = "marekbyd";
            int results = 0;

            DataRow[] returnedRows;

            returnedRows = ds1.Tables["Wpisy"].Select("kod_firmy='" + searchFor + "'");

            results = returnedRows.Length;

            if (results > 0)
            {
                DataRow dr1;

                dr1 = returnedRows[0];

                MessageBox.Show(dr1["nazwa_firmy"].ToString());
            }
            else
            {
                MessageBox.Show("No such Record");
            }
        }



        private void cmbupdate_Click(object sender, EventArgs e)
        {
            System.Data.SqlClient.SqlCommandBuilder cb;
            cb = new System.Data.SqlClient.SqlCommandBuilder(da);

            System.Data.DataRow dRow2 = ds1.Tables["Wpisy"].Rows[inc];

            dRow2[1] = textBox1.Text.ToString();
            dRow2[2] = textBox2.Text.ToString();
            dRow2[3] = textBox3.Text.ToString();


            da.Update(ds1, "Wpisy");

            MessageBox.Show("Data Updated");


        }





    }
}
0

mozna dodac rekord ale po restarcie aplikacji juz go nie widac
sam przycisk 'update' wywiesza aplikacje wyrzucaja powyzszy blad

uzywam c# vs2008 ee i sql server 2005 (darmowe)

1 użytkowników online, w tym zalogowanych: 0, gości: 1