473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

GridView does not show updated data

5
Hi,

When I click the update button on my Gridview to update oracle database, it does not show the updated values.. I need help urgently

Expand|Select|Wrap|Line Numbers
  1. protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  2.     {
  3.  
  4.         OracleConnection oCon = new OracleConnection("Data Source=PSM1;User ID=MASTER;Password=MASTER");
  5.         OracleCommand oCom = new OracleCommand("UPDATE SSU_EMPDETAILS SET SALARY_MODELING = 'salMod', APPL_GA20 = 'applGa20' WHERE UNIQUE_NO = 'unqNo'", oCon);
  6.         oCom.Parameters.Add("unqNo", OracleDbType.Varchar2);
  7.         oCom.Parameters.Add("salMod", OracleDbType.Varchar2);
  8.         oCom.Parameters.Add("applGa20", OracleDbType.Varchar2);
  9.  
  10.         oCom.Parameters["unqNo"].Value = GridView1.DataKeys[e.RowIndex].Value.ToString();
  11.         oCom.Parameters["salMod"].Value = GridView1.Rows[e.RowIndex].Cells[7].Controls[0];
  12.         oCom.Parameters["applGa20"].Value = GridView1.Rows[e.RowIndex].Cells[8].Controls[0];
  13.  
  14.         oCon.Open();
  15.         oCom.ExecuteNonQuery();
  16.         oCon.Close();
  17.         GridView1.EditIndex = -1;
  18.         //GridView1.DataBind();
  19.         BindData();
  20.  
  21.     }
  22.  
  23.     private void BindData()
  24.     {
  25.         OracleConnection oCon = new OracleConnection("Data Source=PSM1;User ID=CHRHRDM;Password=CHRHRDM");
  26.         OracleDataAdapter oDa = new OracleDataAdapter("Select * from SSU_EMPDETAILS", oCon);
  27.         //OracleDataAdapter oDa = new OracleDataAdapter("Select UNIQUE_NO,SALARY_MODELING,APPL_GA20 from SSU_EMPDETAILS", oCon);
  28.         System.Data.DataSet oDs = new DataSet();
  29.         oDa.Fill(oDs);
  30.         GridView1.DataSource = oDs;
  31.         GridView1.DataBind();
  32. }
Feb 17 '10 #1
11 3977
tlhintoq
3,525 Expert 2GB
Database How-to parts 1 and 2
Database tutorial Part 1
Database tutorial Part 2

TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Feb 17 '10 #2
Frinavale
9,735 Expert Mod 8TB
I've never seen parameters used without the "@" symbol....

I would have thought that your SQL query would have to look like this:
Expand|Select|Wrap|Line Numbers
  1. UPDATE SSU_EMPDETAILS SET SALARY_MODELING = @salMod, APPL_GA20 = @applGa20 WHERE UNIQUE_NO = @unqNo
And that you would add your parameters like this:
Expand|Select|Wrap|Line Numbers
  1. oCom.Parameters.Add("@salMod", OracleDbType.Varchar2);
  2. oCom.Parameters.Add("@applGa20", OracleDbType.Varchar2);
  3. oCom.Parameters.Add("@unqNo", OracleDbType.Varchar2);
And you would supply the values like this:
Expand|Select|Wrap|Line Numbers
  1. oCom.Parameters["@unqNo"].Value = GridView1.DataKeys[e.RowIndex].Value.ToString();
  2. oCom.Parameters["@salMod"].Value = GridView1.Rows[e.RowIndex].Cells[7].Controls[0];
  3. oCom.Parameters["@applGa20"].Value = GridView1.Rows[e.RowIndex].Cells[8].Controls[0];
  4.  
-Frinny
Feb 17 '10 #3
Nonki
5
@Frinavale
Hi Frinny,

At first my parameter had an "@" symbol but when I executed my code, I got an error saying "illegal Variable name" only then I realized that Oracle does not like "@" sign used with with parameter name.
Feb 18 '10 #4
Frinavale
9,735 Expert Mod 8TB
I have no experience working with Oracle through .NET
I should have consulted MSDN before posting my last post...

The MSDN Library is your best resource when developing any type of application in .NET. It contains many articles on every topic and it is where I usually go to for help first when I'm stuck on a problem. I recommend that you bookmark the MSDN Library link so that you can always have a reference to it when you are having problems.

Here are 2 articles that I think you'll be interested in reading: the article on the OracleCommand.Parameters Property and also the article on the OracleParameter Class.

Happy Coding!

-Frinny
Feb 18 '10 #5
Try FastSQLDataSource. It helps when you need faster display of large amounts of MS SQL Server data in your web application using grids, lists and other bound controls.
It supports automatic paging and sorting and performs very quickly on large amounts of data
It can work almost without coding or sometimes with no coding at all.
Feb 19 '10 #6
Frinavale
9,735 Expert Mod 8TB
Thanks for the info Anotherone... but Nonki is using Oracle.

-Frinny
Feb 19 '10 #7
Sorry, then just remove my post.
Feb 19 '10 #8
Frinavale
9,735 Expert Mod 8TB
:) We don't delete useful information. Someone my come across this thread that isn't using oracle and may find your post useful. Its nice to learn about new controls once and a while even if it isn't all that helpful to the original question.
Feb 19 '10 #9
semomaniz
210 Expert 100+
Please use try catch block in your code. If there is an error this will reveal it. Also check the database itself if the data has been updated.

Also check you data type, your unique id is set to varchar is that right?
Feb 19 '10 #10
Nonki
5
Hi Guys,

I have changed my code as following and it updates nicely :)

Expand|Select|Wrap|Line Numbers
  1. OracleConnection oCon = new OracleConnection("Data Source=PSM1;User ID=MASTER;Password=MASTER");
  2.  
  3. string unqNo = GridView1.DataKeys[e.RowIndex].Value.ToString();
  4. string salMod = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
  5. string applGa20 = ((TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text;
  6.  
  7. string strSq = "UPDATE SSU_EMPDETAILS SET SALARY_MODELING = '" + salMod + "', APPL_GA20 = '" + applGa20 Where UNIQUE_NO = '" + unqNo + "' ;
  8.  
  9. OracleCommand oCom = new OracleCommand(strSq, oCon);
  10.  
  11. oCon.Open();
  12. oCon.Close();
  13. GridView1.EditIndex = -1;
  14. BindData();
  15.  

Does anyone know how to update a Date field in this way??

Thanks Everyone
Feb 22 '10 #11
CroCrew
564 Expert 512MB
Hello Nonki,

The code you just posted may do what you want it to do but, it is very vulnerable to SQL injection attacks.

I would find an alternative way of inserting into your database.

Happy Coding,
CroCrew~
Feb 22 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
1
by: Raja | last post by:
Hi Everybody Just playing with ObjectDataSource and noticed the following. I have a Gridview which binds to a ObjectDataSource. ObjectDataSource gets data from a typed dataset created with VWD. In...
1
by: needin4mation | last post by:
Not sure what I'm doing wrong here. I have a gridview and a detailsview. The detailsview is set to insert by default. When I insert data the detailsview it works. The data goes in the database....
3
by: slemen | last post by:
The controls (textboxes) in the gridview row being updated have the old, pre user updated values in the RowUpdating event. Does anyone have an idea why? Thank you, Scott
3
by: pblack9455 | last post by:
I have a simple requirement to bind a small ArrayList of (ItemLine) Objects to a GridView control. The Gridview renders on the page and allows me to click update/edit buttons...however the data...
0
by: cmrhema | last post by:
Hello, I am having a problem with GRIDVIEW IN C#. The following code updates only the alternate rows. When i use the edit button all the cells does get converted to textboxes thereafter when i...
2
by: shapper | last post by:
Hello, I am working with a ListView but I suppose that with a GridView might be the same. Instead of having an Insert Button on each GridView row I would like to have only one Insert button,...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.