473,799 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database updation through datagridview

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

Mar 26 '07 #1
4 2268
http://msdn2.microsoft.com/en-us/lib...32(VS.80).aspx

Robin S.
--------------------------
"Neeraj" <kn*******@gmai l.comwrote in message
news:11******** *************@n 76g2000hsh.goog legroups.com...
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

Mar 27 '07 #2
I don't know if I am helping but htis code below works for me. I am saving to
two tables below:

this.Validate() ;
this.scriptBind ingSource.EndEd it();
this.scriptIDBi ndingSource.End Edit();

try
{
// Update the Script tables.
scriptIDTableAd apter.Update(fi xed1DataSet.Scr iptID);
scriptTableAdap ter.Update(fixe d1DataSet.Scrip t);

}

catch (System.Excepti on ex)
{
MessageBox.Show ("Operation failed: " + ex.ToString),
Application.Pro ductName + " - Error", MessageBoxButto ns.OK,
MessageBoxIcon. Error);
}
"Neeraj" wrote:
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

Mar 28 '07 #3
bob
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
Mar 28 '07 #4
On Mar 28, 8:52 am, bob <startatbob_cl. ..@cutthis.adri ley.co.nz>
wrote:
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" <kneera...@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- Hide quoted text -

- Show quoted text -
Thanks Bob
I got it

Mar 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2826
by: Sylesh Nair | last post by:
could anyone give me a possible solution for a Windows Service (in C#) listening to a table in a database for insertion or updation. thanks
16
2784
by: Vibhu | last post by:
Hello All, I am trying to update a database using dataset but seems that I am missing out something. After going through a lot of posts and checking my code, I am still at my wits end to figure out how to do a simple update. Here is the code. Any help would be greatly appreciated. Regards,
1
2039
by: r2destini | last post by:
Hi Friends, I am new to .Net. So I don't know much. I am facing a problem in updating database through ADO.Net I am creating the dataset and there is no problem in the updation and deletion or insertion in the dataset but when I am updating the
0
1298
by: prashant | last post by:
Hi, I am trying to set up Transactional replication with immediate updation. The configuration is as follows: 1. Publisher is SQL server 2000 Enterprise Edition, and Distributor is on the same server. 2. Publisher SQL server is installed on Windows 2003.
0
1123
by: jmanuel | last post by:
Hi, I'm using datagridview in vb2005. I'm populating datagridview at run time using SqlDataAdapter and a dataset. This is my situation. User may update some of the records in the datagridview. When user press Update button, his userid must be updated to those updated records(user id is stored in a global varibale). How do I do it? Thanks for your suggestions.
2
15533
by: Steve Richter | last post by:
what is the best way to use DataGridView to view data from large database tables? Where the sql select statement might return millions of rows? string connectionString = GetFinancesConnString(); string sqlSelect = "select CheckNbr, CheckDate, CheckAmt from Disbursements" ; SqlDataAdapter adapter = new SqlDataAdapter(sqlSelect, connectionString);
2
2236
by: snowdog17 | last post by:
Hello, I am a student and I need help with my VB task. I am currently using VB 2005 Express and I am fairly new to it, although I have programed in Delphi before. -------------------------------------- My Problem is this: -------------------------------------- I have 2 forms. The first form contains a DataGridView and a button. The DataGridView is bound to an access database, and loads at form_load. The second form contains several...
1
1686
by: siri11 | last post by:
Hi everyone!!!!!!!!! If i update a record in a table in sqlserver from front end (c#.net),using a stored procedure for updating then after updation if i open the table then it is showing the same record 2 times i.e before updation record and after updation record..Plzzzzzzzz help me how to solve this problem....its very urgent...Plzzzzzzzzzz Thanks in advance siri
2
1756
by: saga git | last post by:
how to write javascript validations for database updation
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.