oto kod
prosze o poradę.
Zadeklarowałem przestrzeń nazw więc nie powinno tak się dziać
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;
using System.Configuration;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private String connectionString = null;
private SqlConnection sqlConnection = null;
private SqlDataAdapter sqlDataAdapter = null;
private SqlCommandBuilder sqlCommandBuilder = null;
private DataTable dataTable = null;
private BindingSource bindingSource = null;
private String selectQueryString = null;
public Form1()
{
InitializeComponent();
}
private void pracownicyBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.pracownicyBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.hityFilmoweDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
connectionString = ConfigurationManager.AppSettings["connectionString"];
sqlConnection = new SqlConnection(connectionString);
selectQueryString = "SELECT * FROM Pracownicy";
sqlConnection.Open();
sqlDataAdapter = new SqlDataAdapter(selectQueryString, sqlConnection);
sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter);
dataTable = new DataTable();
sqlDataAdapter.Fill(dataTable);
bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
a.DataSource = bindingSource;
// if you want to hide Identity column
a.Columns[0].Visible = false;
// TODO: This line of code loads data into the 'hityFilmoweDataSet.Pracownicy' table. You can move, or remove it, as needed.
this.pracownicyTableAdapter.Fill(this.hityFilmoweDataSet.Pracownicy);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
sqlDataAdapter.Update(dataTable);
}
catch (Exception exceptionObj)
{
MessageBox.Show(exceptionObj.Message.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
a.Rows.RemoveAt(a.CurrentRow.Index);
sqlDataAdapter.Update(dataTable);
}
catch (Exception exceptionObj)
{
MessageBox.Show(exceptionObj.Message.ToString());
}
}
}
}