473,788 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

not able to display data in datagrid

16 New Member
First i would like to thank those persons who helped me out in solving my earlier problems
the present problem is that i am unable to display data in datagrid....... but the data is visible in database..below is the code
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  3.             if (!Page.IsPostBack)
  4.             {
  5.                 BindData();
  6.             }
  7.  
  8.  
  9.             // Put user code to initialize the page here
  10.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" );
  11.             DataSet ds = new DataSet();
  12.             da.Fill(ds,"CMRS_BUSINESSAREA_MASTER");
  13.             DataGrid1.DataSource = ds.Tables["CMRS_BUSINESSAREA_MASTER"].DefaultView ;
  14.             DataGrid1.DataBind();
  15.  
  16.         }
  17.  
  18.  
  19.         public void BindData()
  20.         {
  21.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" ); 
  22.             DataSet ds = new DataSet(); 
  23.             da.Fill(ds);
  24.  
  25.             DataGrid1.DataSource = ds.Tables[0].DefaultView ;
  26.             DataGrid1.DataBind();
  27.  
  28.  
  29.         }
  30.         public void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  31.         {
  32.             DataGrid1.EditItemIndex = e.Item.ItemIndex;
  33.             BindData(); 
  34.         }
  35.  
  36.         public void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  37.         {
  38.             DataGrid1.EditItemIndex = -1; 
  39.             BindData(); 
  40.         }
  41.  
  42.         public void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  43.         {
  44.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
  45.             OleDbConnection con1 = new OleDbConnection();
  46.             con1.ConnectionString = str;
  47.  
  48.  
  49.             TextBox txtAREADESCRIPTION =(TextBox) e.Item.Cells[1].Controls[0];
  50.             string strUpdateStmt;
  51.  
  52.             strUpdateStmt = "UPDATE CMRS_BUSINESSAREA_MASTER SET " + "CBM_BUSAREA_DESC = '" + txtAREADESCRIPTION.Text + "' " + "WHERE CBM_BUSAREA_CODE ='" + e.Item.Cells[0].Text +"'";
  53.  
  54.             cmd = new OleDbCommand(strUpdateStmt,con1);
  55.             con1.Open();
  56.             cmd.ExecuteNonQuery();         
  57.             DataGrid1.EditItemIndex = -1;
  58.             BindData();
  59.         }
  60.  
  61.  
  62.         #region Web Form Designer generated code
  63.         override protected void OnInit(EventArgs e)
  64.         {
  65.             //
  66.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  67.             //
  68.             InitializeComponent();
  69.             base.OnInit(e);
  70.         }
  71.  
  72.         /// <summary>
  73.         /// Required method for Designer support - do not modify
  74.         /// the contents of this method with the code editor.
  75.         /// </summary>
  76.         private void InitializeComponent()
  77.         {    
  78.             this.cmd = new System.Data.OleDb.OleDbCommand();
  79.             this.con1 = new System.Data.OleDb.OleDbConnection();
  80.             this.addbtn.Click += new System.EventHandler(this.addbtn_Click);
  81.             this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
  82.             this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
  83.             this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
  84.             this.Load += new System.EventHandler(this.Page_Load);
  85.  
  86.         }
  87.         #endregion
  88.  
  89.         private void addbtn_Click(object sender, System.EventArgs e)
  90.         {
  91.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString();  
  92.  
  93.             OleDbConnection con1 = new OleDbConnection();
  94.             con1.ConnectionString = str;
  95.             OleDbCommand cmd = new OleDbCommand("Insert into cmrs_businessarea_master values('"+TextBox1.Text+"','"+TextBox2.Text+"')",con1);         
  96.             con1.Open();
  97.             cmd.ExecuteNonQuery();
  98.             con1.Close();
  99.             BindData();
  100.  
  101.  
  102.         }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.     }
  110.  
  111.  
  112.  
  113. }
Jul 25 '07 #1
1 1432
dip_developer
648 Recognized Expert Contributor
First i would like to thank those persons who helped me out in solving my earlier problems
the present problem is that i am unable to display data in datagrid....... but the data is visible in database..below is the code
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  3.             if (!Page.IsPostBack)
  4.             {
  5.                 BindData();
  6.             }
  7.  
  8.  
  9.             // Put user code to initialize the page here
  10.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" );
  11.             DataSet ds = new DataSet();
  12.             da.Fill(ds,"CMRS_BUSINESSAREA_MASTER");
  13.             DataGrid1.DataSource = ds.Tables["CMRS_BUSINESSAREA_MASTER"].DefaultView ;
  14.             DataGrid1.DataBind();
  15.  
  16.         }
  17.  
  18.  
  19.         public void BindData()
  20.         {
  21.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" ); 
  22.             DataSet ds = new DataSet(); 
  23.             da.Fill(ds);
  24.  
  25.             DataGrid1.DataSource = ds.Tables[0].DefaultView ;
  26.             DataGrid1.DataBind();
  27.  
  28.  
  29.         }
  30.         public void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  31.         {
  32.             DataGrid1.EditItemIndex = e.Item.ItemIndex;
  33.             BindData(); 
  34.         }
  35.  
  36.         public void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  37.         {
  38.             DataGrid1.EditItemIndex = -1; 
  39.             BindData(); 
  40.         }
  41.  
  42.         public void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  43.         {
  44.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
  45.             OleDbConnection con1 = new OleDbConnection();
  46.             con1.ConnectionString = str;
  47.  
  48.  
  49.             TextBox txtAREADESCRIPTION =(TextBox) e.Item.Cells[1].Controls[0];
  50.             string strUpdateStmt;
  51.  
  52.             strUpdateStmt = "UPDATE CMRS_BUSINESSAREA_MASTER SET " + "CBM_BUSAREA_DESC = '" + txtAREADESCRIPTION.Text + "' " + "WHERE CBM_BUSAREA_CODE ='" + e.Item.Cells[0].Text +"'";
  53.  
  54.             cmd = new OleDbCommand(strUpdateStmt,con1);
  55.             con1.Open();
  56.             cmd.ExecuteNonQuery(); 
  57.             DataGrid1.EditItemIndex = -1;
  58.             BindData();
  59.         }
  60.  
  61.  
  62.         #region Web Form Designer generated code
  63.         override protected void OnInit(EventArgs e)
  64.         {
  65.             //
  66.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  67.             //
  68.             InitializeComponent();
  69.             base.OnInit(e);
  70.         }
  71.  
  72.         /// <summary>
  73.         /// Required method for Designer support - do not modify
  74.         /// the contents of this method with the code editor.
  75.         /// </summary>
  76.         private void InitializeComponent()
  77.         { 
  78.             this.cmd = new System.Data.OleDb.OleDbCommand();
  79.             this.con1 = new System.Data.OleDb.OleDbConnection();
  80.             this.addbtn.Click += new System.EventHandler(this.addbtn_Click);
  81.             this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
  82.             this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
  83.             this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
  84.             this.Load += new System.EventHandler(this.Page_Load);
  85.  
  86.         }
  87.         #endregion
  88.  
  89.         private void addbtn_Click(object sender, System.EventArgs e)
  90.         {
  91.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString(); 
  92.  
  93.             OleDbConnection con1 = new OleDbConnection();
  94.             con1.ConnectionString = str;
  95.             OleDbCommand cmd = new OleDbCommand("Insert into cmrs_businessarea_master values('"+TextBox1.Text+"','"+TextBox2.Text+"')",con1);         
  96.             con1.Open();
  97.             cmd.ExecuteNonQuery();
  98.             con1.Close();
  99. BindData(); 
  100.         } 
  101.     } 
  102. }
I didnt understand your logic......why the code between line 9 and 14 in Page_Load event...you are calling BinData() first time when page loads...thats fine...then why are you again binding the grid.......outs ide if block in Page_Load....
Jul 25 '07 #2

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

Similar topics

3
2230
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if he row.delete() in my Delete_Row sub is correct because when deleting a record from the dbase, it doesnot get deleted from the actual database, even tho on the datagrid it does show that the record is deleted: '''''''''''''
18
3352
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those columns, "scode" and "sname", as 1 column (if not possible then 2 columns will be fine) in the listbox. Can the listbox display 2 columns information from the dataset and how can I do that? Also, I set the property of the listbox to selectionmode...
3
4237
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the datatable feeding the datagrid control. Both are of the DateTime Type. How do I get the time field to display only the Time, and not the date, which is apparently the default.
1
5291
by: Craig Banks | last post by:
If a row of data in a dataset has a lot of columns the row displaying the data in a datagrid will run way off the screen. What I'd like to do is display a row of data over several datagrid rows so the user doesn't have to scroll horizontally. Essentially, I want to wrap a datagrid row (not text in individual columns) with as much control as possible. Make sense? While this seems simple enough on the surface, I can't figure out how to do...
3
2784
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using System.Collections; using System.ComponentModel; using System.Data;
2
3137
by: harry | last post by:
Hi all, I have a datagrid (language C#) populated using a stored procedure. I want one of the column to display complete name instead of abbreviation. Can I change the display dynamically in the datagrid or should I change it in stored procedure?
11
1931
by: tshad | last post by:
I have a Windows form where I am trying to set the BackColor of a control and check the color before I do it: If control.BackColor = System.Drawing.Color.Blue Then ChangeColor(control, Color.Red) Else ChangeColor(control, Color.Blue) End If But I get an error:
2
2800
by: pozze | last post by:
Hi, I need to display images and other record information retrieved from an SQL 2005 database in a datagrid on a web page. I'm coding in VB .net I have recently changed over from VB ASP and i'm still getting used to .net I can successfully upload images and other data into the SQL Database, I'm currently storing RecordID, File Name, Type of File (mime), File Size, and File Data. I can retreive non binary data to a datagrid but I cannot...
2
1616
by: simonyong | last post by:
hello, anyone.. im newbie to asp.net my problem is : My task is related to view all data from a table called "employee " i had create a datagrid where called data from database and successfully display in a datagrid.. each employee will hav their own personnel_number and direct_manager_personnel_number which refer to who is his/her direct boss... eg.
0
9656
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
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9967
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
8993
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...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
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();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
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.