Hi Neeraj,
You need to create an update command and attach it to the dataadapter,
Some working code follows
Seeing you are not using stored procedures. The Update and insert
strings become SQL text with parameter holders.
e.g.(From memory)
Update myTable set myColumn = ? where myOtherColumn = ?
Ignore the factory use in the following code.
You can see making of:
The command
The command string
The parameters and their binding to the dataset columns
The attachment of the command to the dataadapter
hth
Bob
public bool WriteBatchStatu s(dsBatchAssign able ds)
{
string strSQL;
long j=0;
DbCommand cmdConn = df.CreateComman d();
DbDataAdapter dUpdate = df.CreateDataAd apter();
DbConnection Con = df.CreateConnec tion();
try
{
strSQL = "proc_WriteBatc hStatus";
Con.ConnectionS tring = mstrConnectionS tring;
cmdConn.Connect ion = Con;
DbParameter pBId = df.CreateParame ter();
DbParameter pSId = df.CreateParame ter();
pBId.ParameterN ame = "@Batch_id" ;
pSId.ParameterN ame = "@Supplier_ id";
pBId.DbType = DbType.Int32;
pSId.DbType = DbType.Int32;
pBId.SourceColu mn = "id";
pSId.SourceColu mn = "supplier_i d";
cmdConn.Paramet ers.Add(pBId);
cmdConn.Paramet ers.Add(pSId);
cmdConn.Command Text = strSQL;
cmdConn.Command Type = CommandType.Sto redProcedure;
dUpdate.UpdateC ommand = cmdConn;
cmdConn.Connect ion.Open();
dUpdate.Update( ds.Tables["batchassignabl e"]);
cmdConn.Connect ion.Close();
cmdConn.Dispose ();
return true;
}
On 26 Mar 2007 03:57:59 -0700, "Neeraj" <kn*******@gmai l.comwrote:
>hi
I am using datagridview and sql Express as a datasource i populate
data but not able to update through datagridview
i am using such code
dataAdpter = new System.Data.Sql Client.SqlDataA dapter("select MGenID,
General, status from General where status = 1", connect);
dataset = new DataSet();
dataAdpter.Fill (dataset, nodeValue);
grdMastervalue. DataSource = dataset.Tables[0];
data is showing proporly
for update the data i write code on button click event
private void btnEdit_Click(o bject sender, EventArgs e)
{
this.Validate() ;
this.grdMasterv alue.EndEdit();
this.dataAdpter .Update(this.da taset, nodeValue);
}
then last line generate exception
An unhandled exception of type 'System.Invalid OperationExcept ion'
occurred in System.Data.dll
Additional information: Update requires a valid UpdateCommand when
passed DataRow collection with modified rows.
Please tell where i am wrong
thanks
Neeraj Kumar