You should read more about
ADO.Net basics.
Then you should learn about LINQ and if you still have desire to be a coder you should learn about Entity framework.
And try to look for answers yourself, this topic isn't esoteric ;)!
http://www.youtube.com/watch?v=4kBXLv4h2ig&feature=related
When it comes to ADO.Net every action related to transfer of data to or from database needs two things:
open connection and DBCommand object(SqlCommand, OledbCommand, Odbc... they all inherit from DBCommand class).
DataAdapter is "middle man" between datatables and commands.
Data binding is nothing more than connecting values on controls with data within particular DataRow, after you are done with changes those updates can be sent to DB or scrapped.
First of all you need data set (preferably with adapters).
You can bind data to the consumer form in three ways:
1. From Data Sources window, you simply choose table from your data set and drag and drop column representations to your form. This way everything is done by IDE for you.
2. You add binding source component to consumer form from Tools window and connecting it to the data set or data table within data set. Then you bind particular controls on your form to values from binding source.
3. Do all by hand. I wouldn't go there :).
Addendum:
I recommend this recipe:
DoubleClick for editing selected row and explicit Add new row call (via button or something).
This is simplified version.
First you must set your dataGridView
myDataGridView.DataSource = myDataSet;
myDataGridView.DataMember = "TableName";
myDataGridView.AllowUserToAddRows = false;
myDataGridView.DoubleClick += new EventHandler(myDataGridView_DoubleClick);
Event handler for double click can be something like this:
void myDataGridView_DoubleClick(object sender, EventArgs e)
{
if(myDataGridView.SelectedRows.Count > 0)
{
int rowID = (int)myDataGridView.SelectedRows[0].Cells["IDColumn"].Value;
MyDataInputForm frm = new MyDataInputForm();
frm.Data = myDataSet;
frm.SetEdit(rowID);
if(frm.ShowDialog() == DialogResult.OK)
{
frm.EndEdit();
}
else
{
frm.CancelEdit();
}
}
}
For adding new row you can call (from toolbar, button...) method like this
void AddNewRow()
{
DatSet copy = myDatSet.Copy();
MyDataInputForm frm = new MyDataInputForm();
frm.Data = copy;
DataRow dr = copy.Tables["TableName"].NewRow();
copy.Tables["TableName"].Rows.Add(dr);
frm.SetEdit((int)dr["IDColumn"]);
if(frm.ShowDialog() == DialogResult.OK)
{
frm.EndEdit();
myDatSet.Clear();
myDatSet.Merge(copy);
}
else
{
frm.CancelEdit();
}
}
MyDataInputForm inherits from IDataEditor<t> interface
public interface IDataEditor<t>
{
void CancelEdit();
void EndEdit();
void SetEdit(T objectID);
DataSet Data { get; set; }
}</t>
public partial class MyDataInputForm : Form, IDataEditor<int>
{
public MyDataInputForm ()
{
InitializeComponent();
}
public void CancelEdit()
{
this.myBindingSource.CancelEdit();
}
public void EndEdit()
{
this.myBindingSource.EndEdit();
}
public void SetEdit(int objectID)
{
this.myBindingSource.Filter = "IDColumn=" + objectID;
Application.DoEvents();
}
public DataSet Data
{
get
{
return this.dataSet;
}
set
{
this.dataSet= value;
this.myBindingSource.DataSource = value;
this.myBindingSource.DataMember = "TableName";
}
}
}</int>
You can change IDataEditor.Data to your custom typed dataSet.
Friendly advice to conclude this:
Don't rely to much on directly manipulating data with dataGridView unless you know what are you doing or you don't have big validating issues.
Cheers!