473,387 Members | 1,453 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,387 software developers and data experts.

Problem related to insert/update record

navneetkaur
Updation Should Reflect at same time
hi every1
i am stuck at 1 place...i want whatever updation i do it should be reflected at the same time in table(i am using table to display all records)then if i delete 1 record frm this table it shd be reflected at the same time in table....bt its not working i am using following codeplz help me....m waiting fr ur response....


code is
Expand|Select|Wrap|Line Numbers
  1.         SqlCommand cmd;
  2.         string str;
  3.         conn.Open();
  4.         str = "update cur_month_ach set active = 0 where rowid=" + rwid + "";
  5.         cmd = new SqlCommand(str, conn);
  6.         int temp = cmd.ExecuteNonQuery();
  7.         conn.Close();
  8.  
'd there is 1 html table in which i displayed all these records 'd there is 1 command button deactivate....when i click on this i pass row id 'd above procedure is called.....
Sep 18 '07 #1
16 1479
After Updation you must have to fetch data again from the table and show it in table.

Updation Should Reflect at same time
hi every1
i am stuck at 1 place...i want whatever updation i do it should be reflected at the same time in table(i am using table to display all records)then if i delete 1 record frm this table it shd be reflected at the same time in table....bt its not working i am using following codeplz help me....m waiting fr ur response....


code is
Expand|Select|Wrap|Line Numbers
  1.         SqlCommand cmd;
  2.         string str;
  3.         conn.Open();
  4.         str = "update cur_month_ach set active = 0 where rowid=" + rwid + "";
  5.         cmd = new SqlCommand(str, conn);
  6.         int temp = cmd.ExecuteNonQuery();
  7.         conn.Close();
  8.  
'd there is 1 html table in which i displayed all these records 'd there is 1 command button deactivate....when i click on this i pass row id 'd above procedure is called.....
Sep 18 '07 #2
After Updation you must have to fetch data again from the table and show it in table.
hello mohit thanx a lot fr reply
but i hv nt done so because it vl create overhead on system...this table creation is called during pageload event.....bt acc to me coz of page life cycle its nt updating....
sp olz if u hv any idea help me...m waiting
Sep 18 '07 #3
Hi Navneet
You might hv written your code in
if(!Page.IsPostBack)
{
//your code
}
So according to page's life cycle this code will not run again untill postback is not equal to false again. So after updating ur database u have to rebind ur table.
I think thats the only way...

hello mohit thanx a lot fr reply
but i hv nt done so because it vl create overhead on system...this table creation is called during pageload event.....bt acc to me coz of page life cycle its nt updating....
sp olz if u hv any idea help me...m waiting
Sep 19 '07 #4
Hi Navneet
You might hv written your code in
if(!Page.IsPostBack)
{
//your code
}
So according to page's life cycle this code will not run again untill postback is not equal to false again. So after updating ur database u have to rebind ur table.
I think thats the only way...
hi mohit....
i have jst added this fxn without checking ispostback it is executed at every time......its already rebuilding after every postback....nw plz if u hv solution tell me....
Sep 19 '07 #5
Frinavale
9,735 Expert Mod 8TB
hello mohit thanx a lot fr reply
but i hv nt done so because it vl create overhead on system...this table creation is called during pageload event.....bt acc to me coz of page life cycle its nt updating....
sp olz if u hv any idea help me...m waiting
If you create the table (the data source for your GridView) with every page load your Update function will not work.

You should only create the table (the data source for your GridView) only once...when it is Not Postback... and store the table somewhere (like Session) so that you don't have to recreate it every time your page is loaded.....this is good practice for Many reasons. (One reason being that all of the data a user provides for an Update will be lost when you recreate the DataSource for the GridView in the PageLoad....because the original data is lost when the DataSource is changed...and the PageLoad event happens before the Update event occurs...)

Once you have completed your Delete or Update you should recreate the table (the data source for your GridView)...then DataBind your GridView to the Updated DataSource to reflect the changes.

-Frinny
Sep 19 '07 #6
Hi Navneet
You told that you have not checked 'ispostback' property. I think your data might be updated because when you click update button first pageload event will be fired where u have wriiten your gridbind code, So when page load fires again it will take data from original data and the chngd values will be lost. Check your data in query analyzer that it is updatied or not.
seq of event is Page_load->Button_Click
you can check this by putting breakpoints in your code.
So i think you must put ur grid binding proc. in postback event.
If u still getting prblm then give me more details abt ur code.
Hope it will work....
hi mohit....
i have jst added this fxn without checking ispostback it is executed at every time......its already rebuilding after every postback....nw plz if u hv solution tell me....
Sep 20 '07 #7
If you create the table (the data source for your GridView) with every page load your Update function will not work.

You should only create the table (the data source for your GridView) only once...when it is Not Postback... and store the table somewhere (like Session) so that you don't have to recreate it every time your page is loaded.....this is good practice for Many reasons. (One reason being that all of the data a user provides for an Update will be lost when you recreate the DataSource for the GridView in the PageLoad....because the original data is lost when the DataSource is changed...and the PageLoad event happens before the Update event occurs...)

Once you have completed your Delete or Update you should recreate the table (the data source for your GridView)...then DataBind your GridView to the Updated DataSource to reflect the changes.

-Frinny
First of all Thanx Sir.....i got ur point bt i am not able to do like that coz whenever i place this table creation on PageLoad as ispostback property...it disappear from the page....sir i am going to write my code.....plz help me by providing coding.....

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. public partial class _Default : System.Web.UI.Page 
  4. {
  5.     Class1 cls;
  6.     DataSet ds;
  7.  
  8.     int curyear, curmonth;
  9.     string rowid;
  10.     protected void Page_Load(object sender, EventArgs e)
  11.     {
  12.         cls = new Class1();
  13.         ds = new DataSet();
  14.         cur_proj_assigned();  //this is where i am calling table  
  15. //   creation...bt it does nt update without response.redirect(to same page);
  16.  }
  17. //this module is creating table dynamically to display records....
  18.     public void cur_proj_assigned()
  19.     {
  20.             DataSet ds = new DataSet();//to show achievements fr current month
  21.             curmonth = 09;
  22.             curyear = 2007;
  23.             ecode="012345";
  24.             ds = cls.cur_month_ach(ecode, curmonth, curyear);
  25.  
  26.  
  27.             string project_title, project_description, div_name = "";
  28.             string div_code;
  29.             Modcur.EnableViewState = true;
  30.             if (ds.Tables[0].Rows.Count > 0)
  31.             {
  32.  
  33.                 HtmlTableRow r3 = new HtmlTableRow();
  34.                 HtmlTableCell c5 = new HtmlTableCell();
  35.                 c5.ColSpan = 5;
  36.                 c5.Align = "left";
  37.                 c5.BgColor = "#ccffff";
  38.                 c5.Height = "23px";
  39.                 r3.Cells.Add(c5);
  40.  
  41.                 HtmlTableRow r4 = new HtmlTableRow();
  42.                 HtmlTableCell c6 = new HtmlTableCell();
  43.                 c6.InnerText = "Select";
  44.                 HtmlTableCell c7 = new HtmlTableCell();
  45.                 c7.InnerText = "Project Title ";
  46.                 HtmlTableCell c8 = new HtmlTableCell();
  47.                 c8.InnerText = "Project Description";
  48.                 HtmlTableCell c9 = new HtmlTableCell();
  49.                 c9.InnerText = "Status";
  50.                 HtmlTableCell c10 = new HtmlTableCell();
  51.                 c10.InnerText = " Project Division";
  52.  
  53.                 r4.Cells.Add(c6);
  54.                 r4.Cells.Add(c7);
  55.                 r4.Cells.Add(c8);
  56.                 r4.Cells.Add(c10);
  57.                 r4.Cells.Add(c9);
  58.  
  59.                 Modcur.Rows.Add(r3);
  60.                 Modcur.Rows.Add(r4);
  61.             }
  62.             int temp = ds.Tables[0].Rows.Count;
  63.  
  64.             for (int i = 0; i < temp; i++)
  65.             {
  66.                 string div_name1;
  67.                 DataSet ds1 = new DataSet();
  68.                 rowid = ds.Tables[0].Rows[i][1].ToString();
  69.                 project_title = ds.Tables[0].Rows[i][4].ToString();
  70.                 project_description = ds.Tables[0].Rows[i][5].ToString();
  71.                 c = ds.Tables[0].Rows[i][6].ToString();
  72.                 div_code = ds.Tables[0].Rows[i][7].ToString();
  73.                 if (div_code != "")
  74.                 {
  75.                     div_name1 = cls.fetch_division_name(div_code);
  76.                     div_name = div_name1;
  77.                 }
  78.                 HtmlInputHidden idh = new HtmlInputHidden();
  79.                 RadioButton rd = new RadioButton();
  80.                 rd.GroupName = "rdbtn_grp";
  81.                 rd.ID = "rid" + i;
  82.                 idh.ID = "hhd" + i;
  83.  
  84.                 idh.Value = rowid.ToString();//put database value here
  85.  
  86.                 HtmlTableCell c1 = new HtmlTableCell();
  87.                 c1.ColSpan = 1;
  88.                 c1.Controls.Add(rd);
  89.                 c1.Controls.Add(idh);
  90.  
  91.  
  92.                 TextBox prjtitle = new TextBox();
  93.  
  94.                 prjtitle.TextMode = TextBoxMode.MultiLine;
  95.                 prjtitle.Text = project_title;
  96.                 prjtitle.ReadOnly = true;
  97.                 HtmlTableCell c2 = new HtmlTableCell();
  98.                 c2.ColSpan = 1;
  99.                 c2.Controls.Add(prjtitle);
  100.  
  101.                 TextBox prjdesc = new TextBox();
  102.  
  103.                 prjdesc.TextMode = TextBoxMode.MultiLine;
  104.                 prjdesc.Text = project_description;
  105.                 prjdesc.ReadOnly = true;
  106.                 HtmlTableCell c3 = new HtmlTableCell();
  107.                 c3.ColSpan = 1;
  108.                 c3.Controls.Add(prjdesc);
  109.  
  110.                 TextBox division_txt = new TextBox();
  111.  
  112.                 division_txt.TextMode = TextBoxMode.MultiLine;
  113.                 division_txt.Text = div_name;
  114.                 division_txt.ReadOnly = true;
  115.                 HtmlTableCell c5 = new HtmlTableCell();
  116.                 c5.ColSpan = 1;
  117.                 c5.Controls.Add(division_txt);
  118.  
  119.                 HtmlTableCell c4 = new HtmlTableCell();
  120.                 Label status1 = new Label();
  121.                 if (c == "True")
  122.                 {
  123.                     status1.Text = "Active";
  124.                     c4.BgColor = "99ccff";
  125.                 }
  126.                 else
  127.                 {
  128.                     status1.Text = "DeActive";
  129.                     c4.BgColor = "ccffcc";
  130.                 }
  131.                 c4.ColSpan = 1;
  132.                 c4.Controls.Add(status1);
  133.                 HtmlTableRow r1 = new HtmlTableRow();
  134.                 r1.Cells.Add(c1);
  135.                 r1.Cells.Add(c2);
  136.                 r1.Cells.Add(c3);
  137.                 r1.Cells.Add(c5);
  138.                 r1.Cells.Add(c4);
  139.  
  140.                 Modcur.Rows.Add(r1);
  141.             }
  142.  
  143.             if (ds.Tables[0].Rows.Count > 0)
  144.             {
  145.                Button deactachievements = new Button();
  146.  
  147.                 deactachievements.ID = "deactach";
  148.                 deactachievements.Text = "DeActivate";
  149.                 deactachievements.Click += new EventHandler(deactachievements_Click);
  150.  
  151.                 HtmlTableCell c4 = new HtmlTableCell();
  152.                 c4.ColSpan = 5;
  153.  
  154.                 c4.Controls.Add(deactachievements);
  155.  
  156.                 HtmlTableRow r2 = new HtmlTableRow();
  157.                 r2.Cells.Add(c4);
  158.                 Modcur.Rows.Add(r2);
  159.             }
  160.  
  161.     }
  162.  //click event of delete button of current month added project
  163.     protected void deactachievements_Click(object sender, System.EventArgs e)
  164.     {
  165.            int rowid = 0;
  166.             RadioButton rowid1 = new RadioButton();
  167.             HtmlInputHidden htt = new HtmlInputHidden();
  168.             int i = 0;
  169.             foreach (Control rd in Modcur.Controls)
  170.             {
  171.                 rowid1 = (RadioButton)Modcur.FindControl("rid" + i);
  172.                 htt = (HtmlInputHidden)Modcur.FindControl("hhd" + i);
  173.                 i += 1;
  174.                 if (rowid1 != null && rowid1.Checked)
  175.                     rowid = int.Parse(htt.Value);
  176.             }
  177.             cls.cur_month_deactivate(rowid);
  178.             //Server.Transfer("Default.aspx");
  179.     }
  180. }
Sir i have placed my code this is jst a abstract of full code....sir like above 1 dynamic button DEACTIVATE i hv to attach so many buttons also....Sir plz help me....
Sep 20 '07 #8
Frinavale
9,735 Expert Mod 8TB
First of all Thanx Sir.....i got ur point bt i am not able to do like that coz whenever i place this table creation on PageLoad as ispostback property...it disappear from the page....sir i am going to write my code.....plz help me by providing coding.....

Sir i have placed my code this is jst a abstract of full code....sir like above 1 dynamic button DEACTIVATE i hv to attach so many buttons also....Sir plz help me....
You are doing Way too much work here.
A GridView has a method called DataBind.
What you do is set your GridView.Source = some Data Set (or something) and then call the GridView.DataBind to "Bind" that data to the GridView.

Please look at the GridView Class as described by MSDN...particularly the following part:

Binding to Data

The GridView control can be bound to a data source control (such as SqlDataSource, ObjectDataSource, and so on), as well as any data source that implements the System.Collections.IEnumerable interface (such as System.Data.DataView, System.Collections.ArrayList, or System.Collections.Hashtable).
.....
To bind to a data source that implements the System.Collections.IEnumerable interface, programmatically set the DataSource property of the GridView control to the data source and then call the DataBind method. When using this method, the GridView control does not provide built-in sorting, updating, deleting, and paging functionality. You need to provide this functionality by using the appropriate event.


Using the DataBind method will get rid of most of your code.
All you need to do is create the DataSource (your data set) Once...in the page load when it is not postback...and store it in Session (or somewhere) so that you don't need to recreate it over and over again....

Please look at the GridView Class (documentation provided by MSDN). You will find a lot of tutorials on this page along with examples and anything else you would like to know.

Cheers!
-Frinny
Sep 20 '07 #9
hi navneet i read ur code.
as i said u r calling ur function "cur_proj_assigned " without ispostback so ur values are not saved.
if u put ur function in postback it will run only one time and u hv to call it after updationation agn and it will not put extra overhead on ur programe. ur function is called with pageload everytime now but after postback it will be called only first time in pageload, and agn whn u called it after button click.
so there will be no prblm related to efficiency of the form.
Sep 21 '07 #10
hi navneet i read ur code.
as i said u r calling ur function " without ispostback so ur values are not saved.
if u put ur function in postback it will run only one time and u hv to call it after updationation agn and it will not put extra overhead on ur programe. ur function is called with pageload everytime now but after postback it will be called only first time in pageload, and agn whn u called it after button click.
so there will be no prblm related to efficiency of the form.

hi mohitkatariya thanx for seeing this...mohit i agree to ur suggestion bt nw actually problem is on this page i am having near abt 12 buttons i have jst posted 1 just coz of convience......then i hv to call this fxn "cur_proj_assigned " on every button click...i vl try this if it works i vl tell u....thanx for spending ur valuable time on this problem.....
Sep 21 '07 #11
You are doing Way too much work here.
A GridView has a method called DataBind.
What you do is set your GridView.Source = some Data Set (or something) and then call the GridView.DataBind to "Bind" that data to the GridView.

Please look at the GridView Class as described by MSDN...particularly the following part:

Binding to Data

The GridView control can be bound to a data source control (such as SqlDataSource, ObjectDataSource, and so on), as well as any data source that implements the System.Collections.IEnumerable interface (such as System.Data.DataView, System.Collections.ArrayList, or System.Collections.Hashtable).
.....
To bind to a data source that implements the System.Collections.IEnumerable interface, programmatically set the DataSource property of the GridView control to the data source and then call the DataBind method. When using this method, the GridView control does not provide built-in sorting, updating, deleting, and paging functionality. You need to provide this functionality by using the appropriate event.


Using the DataBind method will get rid of most of your code.
All you need to do is create the DataSource (your data set) Once...in the page load when it is not postback...and store it in Session (or somewhere) so that you don't need to recreate it over and over again....

Please look at the GridView Class (documentation provided by MSDN). You will find a lot of tutorials on this page along with examples and anything else you would like to know.

Cheers!
-Frinny
thanx sir i do agree with u bt sir acc to my TL requirement it works like that coz sir there are 4 more click events on this table which is nt possible in gridview....so sir plz tell me solution....sir nw i have placed this code in ispostback property bt nw i am nt able to keep this table state 'd rebuild it again on click event..bt sir 2dy i vl complete it..then i let u knw...thanx fr spending ur valuable time....
Sep 21 '07 #12
hi every1 thanx for responding to my problem 'd
according to ur suggestions i placed fxn "cur_proj_assigned" on ispostback event....but nw 1 more problem is encountered that is click event of dynamically button is not fired because of dynamic controls event should be placed either on pageload or init event ... so plz tell me solution what i will do now......'d 1 thing more i am not able to again draw table.....

plz provide me coding if u knw.....
thanks
with warm regards
Navneet
Sep 21 '07 #13
....waiting fr ur respone...its urgent
Sep 21 '07 #14
I think you have seprate ur function in two parts one is for desiging table n other is for binding. desining part is called on page load so that events get registered, while binding function will be called on every button click.
May be it will work. Hope for best...
....waiting fr ur respone...its urgent
Sep 22 '07 #15
Frinavale
9,735 Expert Mod 8TB
hi every1 thanx for responding to my problem 'd
according to ur suggestions i placed fxn "cur_proj_assigned" on ispostback event....but nw 1 more problem is encountered that is click event of dynamically button is not fired because of dynamic controls event should be placed either on pageload or init event ... so plz tell me solution what i will do now......'d 1 thing more i am not able to again draw table.....

plz provide me coding if u knw.....
thanks
with warm regards
Navneet

Are you able to execute your update now?

-Frinny
Sep 24 '07 #16
Are you able to execute your update now?

-Frinny
no sit till nw its not working...i hv done each way ....acc to sugestions.....
plz sir help me....


sir in this i am not able coz the whole table is generated dynamically i cnt seprate design time 'd binding....
waiting fr ur response...
Sep 25 '07 #17

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

Similar topics

1
by: teddysnips | last post by:
SQL Server 2000 I have a stored procedure that uses an extended SPROC to send an email notification to my customers when a document is distributed. However, the SPROC has an unexpected side...
1
by: Thrushed | last post by:
Hi, I have a web service that takes in a record to be added to a database table, simple right? Well one field stores a .wav file converted to a bit array and is of the field type Text. If...
5
by: Mary Litten | last post by:
Hi - (This is my very first post) I have gotten to this point of registering to post because I have been spinning my wheels so long, I believe I am all caught up in the weeds. (and mud) I have...
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
1
by: Jean-Yves | last post by:
Hi. I have a weird problem when I update my database. I am using SQL Server 2000. In my VB.NET application I used Web Services for insert, update, delete. I have a relation between 2 tables in my...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
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,...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.