how to edit datagridview in window application while the database is access.
and the changes should be reflect in database also.
like i displayed some tabe from access database in datagridview. then i want to changes values in datagridview and the new values sud be update in database.
pls someone suggest.
i am looking for this code for a while and have tried almost every technique
thanks in advance
Loading
Suthish NairPosted Oct 25, 2010, 2:27 PM
Posted Oct 25, 2010, 11:07 AM
Suthish NairPosted Oct 25, 2010, 3:56 AM
Sam HobbsPosted Oct 19, 2010, 4:00 PM
Suthish NairPosted Oct 19, 2010, 3:33 PM
Sams link already saying how to connect to DataSource. Rakesh code shows how to do the operations with tables.
What problem your facing. Be specific which area you facing the issue.
Posted Oct 19, 2010, 3:27 PM
and too i couldnt get the navigation menu. in tht
Sam HobbsPosted Oct 19, 2010, 3:07 PM
Posted Oct 19, 2010, 10:03 AM
i tried a lot but couldnot get the thing working .
i just need a datagridview having edit and delete options and that sud affect the database , that too in window.
may i have your email pls . want to have some discussion regrading this . or a working demo , i can pay a little for this as this is very important for me .
thanks.
Rakesh JhaPosted Oct 9, 2010, 9:47 AM
I am attaching the source file.
Posted Oct 8, 2010, 9:14 PM
i have just taken a datagridview and a single update button .thts it .
please explain some design part of gv tht code too.
it will be great helpful to me .
i guess i am quiet near to the result.
thanks.
Posted Oct 8, 2010, 9:13 PM
please explain some design part of gv tht code too.
it will be great helpful to me .
i guess i am quiet near to the result.
thanks.
Rakesh JhaPosted Oct 8, 2010, 8:30 AM
Hi ram,
sorry for late response. i am attaching access database file
Sam HobbsPosted Oct 7, 2010, 8:45 PM
Posted Oct 7, 2010, 3:14 PM
or can u pls upload its working sample with database.
pls
my now my job depends on it.
thanks and waiting ur reply
Rakesh JhaPosted Oct 6, 2010, 11:40 PM
here is example which will help you to work on access database in windows form with datagridview.
1. first add this namespace
using System.Data.OleDb;
2. now write following code for display record in datagridview
protected DataSet ObjDS = new DataSet();
protected String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\HJHMHome.mdb";
private void DischargeForm_Load(object sender, EventArgs e)
{ (OleDbConnection ObjCon = new OleDbConnection(sConnectionString))
{ using (OleDbDataAdapter ObjAdapter = new OleDbDataAdapter("SELECT * FROM Investigation Order by ColOrder", ObjCon))
{ "Investigation");
dgvInvestigation.DataSource = ObjDS.Tables[0];
ObjCon.Close();
}
}
}
3. Update DataGridView on btnUpdate click
if (ObjDS.HasChanges())
{
DataTable dtChanged = new DataTable();
String ObjInvestigation = String.Empty;
String ObjInvestData = String.Empty;
dtChanged = ObjDS.Tables[0].GetChanges();
foreach (DataRow dr in dtChanged.Rows)
{
for (int iColCntr = 1; iColCntr < 6; iColCntr++)
{
ObjInvestigation = String.Empty;
ObjInvestData = String.Empty;
if (dr["Col" + iColCntr + "Name", DataRowVersion.Current].ToString() != dr["Col" + iColCntr + "Name", DataRowVersion.Original].ToString())
ObjInvestigation = "UPDATE Investigation SET Col" + iColCntr + "Name = '" + dr["Col" + iColCntr + "Name", DataRowVersion.Current].ToString().Replace("'", "''") + "' WHERE Col" + iColCntr + "Name = '" + dr["Col" + iColCntr + "Name", DataRowVersion.Original].ToString().Replace("'", "''") + "' AND Col" + iColCntr + "Value = '" + dr["Col" + iColCntr + "Value", DataRowVersion.Original].ToString() + "'";
if (dr["Col" + iColCntr + "Blank", DataRowVersion.Current].ToString() != dr["Col" + iColCntr + "Blank", DataRowVersion.Original].ToString())
ObjInvestData = "INSERT INTO InvestData(IPNo, InvColID, InvData) SELECT '" + txtIPNo.Text.Replace("'", "''") + "','" + dr["Col" + iColCntr + "Value", DataRowVersion.Current].ToString() + "','" + dr["Col" + iColCntr + "Blank", DataRowVersion.Current].ToString() + "'";
if (!String.IsNullOrEmpty(ObjInvestigation))
if (!String.IsNullOrEmpty(ObjInvestData))
ObjInvestData = ObjInvestData + "; " + ObjInvestigation;
else
ObjInvestData = ObjInvestigation;
if (!String.IsNullOrEmpty(ObjInvestData))
{
using (OleDbCommand ObjCommand = new OleDbCommand(ObjInvestData, ObjCon))
{
ObjCommand.CommandTimeout = 99999;
ObjCommand.CommandType = CommandType.Text;
if (ObjCon.State == ConnectionState.Open)
ObjCon.Close();
ObjCon.Open();
if (Convert.ToInt32(ObjCommand.ExecuteScalar()) >= 0)
ObjDS.AcceptChanges();
ObjCon.Close();
}
}
}
}
}