I have a dataset called ds1 filled with 2 tables Employees and Customers
from Northwind database.
I have dropdownList called ddLastName with the following properties:
ddLastName.Data Source = ds1;
ddLastName.Data Member = "Employees" ;
ddLastName.Data TextField = "LastName";
ddLastName.Data Bind();
ddLastName.Item s.Insert(0,"Sel ect:");
I have a label called lblDisplay
I want the label to display the Notes column data of the selected item in
the dropdownList.
My code is causing a NullReferenceEx ception.
Can anyone find out what is the problem please?
------------------------------------
Code: ----------------------------------------------------
<%@ Page language="c#" Codebehind="Web Form9.aspx.cs" AutoEventWireup ="false"
Inherits="WebAp plication2.WebF orm9" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm9 </title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="C#" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; POSITION:
absolute; TOP: 19px"
runat="server" Width="536px" Height="8px"></asp:Label>
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; POSITION:
absolute; TOP: 152px"
runat="server" Width="672px" Height="120px" BorderColor="#3 366CC"
BorderStyle="No ne" BorderWidth="1p x"
BackColor="Whit e" CellPadding="4" >
<FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle>
<SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99"
BackColor="#009 999"></SelectedItemSty le>
<ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#CCC CFF"
BackColor="#003 399"></HeaderStyle>
<PagerStyle HorizontalAlign ="Left" ForeColor="#003 399"
BackColor="#99C CCC" Mode="NumericPa ges"></PagerStyle>
</asp:DataGrid>
<asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px;
POSITION: absolute; TOP: 16px"
runat="server" Width="112px" Height="24px"
AutoPostBack="T rue"></asp:DropDownLis t>
<asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION:
absolute; TOP: 48px" runat="server"
Width="272px" Height="16px" ForeColor="Red" >I want to display notes of
selected employee</asp:Label>
<asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; POSITION:
absolute; TOP: 72px"
runat="server" Width="704px" Height="56px"></asp:Label></form>
</body>
</HTML>
--------------------------------------------------code
behind--------------------------------------------------------------------------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
namespace WebApplication2
{
/// <summary>
/// Summary description for WebForm9.
/// </summary>
public class WebForm9 : System.Web.UI.P age
{
protected DataSet ds1 = new DataSet();
protected System.Web.UI.W ebControls.Labe l lblDisplay;
protected System.Web.UI.W ebControls.Data Grid DataGrid1;
protected System.Web.UI.W ebControls.Labe l lblText;
protected System.Web.UI.W ebControls.Labe l lblSpecific;
protected System.Web.UI.W ebControls.Drop DownList ddLastName;
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!Page.IsPost Back)
{
string connectionStrin g = "data source =localhost; initial catalog
=Northwind; integrated security=true;" ;
SqlConnection sqlConnection1 = new SqlConnection(c onnectionString );
SqlCommand sqlCommand1 = new SqlCommand();
SqlDataAdapter sda1 = new SqlDataAdapter( );
// "dataset defined at class level"
// DataSet ds1 = new DataSet();
sda1.SelectComm and = sqlCommand1;
sda1.SelectComm and.Connection = sqlConnection1;
sda1.SelectComm and.CommandType = CommandType.Tex t;
sda1.SelectComm and.CommandText = "select * from Employees";
sda1.Fill(ds1," Employees");
SqlDataAdapter sda2 = new SqlDataAdapter( );
sda2.SelectComm and = sqlCommand1;
sda2.SelectComm and.Connection = sqlConnection1;
sda2.SelectComm and.CommandType = CommandType.Tex t;
sda2.SelectComm and.CommandText = "select * from Customers";
sda2.Fill(ds1," Customers");
ddLastName.Data Source = ds1;
ddLastName.Data Member = "Employees" ;
ddLastName.Data TextField = "LastName";
ddLastName.Data Bind();
ddLastName.Item s.Insert(0,"Sel ect:");
// to fill with specific cell data
lblSpecific.Tex t = "Displaying specific Data:<br><br>";
lblSpecific.Tex t += ds1.Tables["Employees"].Rows[0]["Notes"].ToString();
// to fill the datagrid
DataGrid1.DataS ource = ds1;
DataGrid1.DataM ember = "Employees" ;
DataGrid1.DataB ind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.ddLastName .SelectedIndexC hanged += new
System.EventHan dler(this.ddLas tName_SelectedI ndexChanged);
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
private void ddLastName_Sele ctedIndexChange d(object sender,
System.EventArg s e)
{
if(ddLastName.S electedIndex != 0)
{
int i = 0;
foreach(DataRow r in ds1.Tables["Employees"].Rows)
{
if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text)
{
lblDisplay.Text = ds1.Tables["Employees"].Rows[i]["Notes"].ToString();
}
i++;
}
}
else
{
lblDisplay.Text = "";
}
}
}
} 12 1684
The problem is that when you click the Dropdown Box, you trigger a postback.
Unfortunately, your Page_Load event only fills the dataset during the
initial GET. So there is no data to be had when you do your Autopostback.
Once a Webform is constructed and the page rendered, the object is
destroyed. You need to arrange for the data to be filled on the initial get
and saved to the cache for example.
cache("ds1)= Ds1
and as an else condition to your if not IsPostback
ds1 = cache("ds1")
page.DataBind() .. . . . .etc
PS: This is a common mistake to make.
HTH
"Bishoy George" <bi****@bishoy. com> wrote in message
news:uN******** ********@TK2MSF TNGP14.phx.gbl. .. I have a dataset called ds1 filled with 2 tables Employees and Customers from Northwind database. I have dropdownList called ddLastName with the following properties:
ddLastName.Data Source = ds1; ddLastName.Data Member = "Employees" ; ddLastName.Data TextField = "LastName"; ddLastName.Data Bind(); ddLastName.Item s.Insert(0,"Sel ect:");
I have a label called lblDisplay
I want the label to display the Notes column data of the selected item in the dropdownList.
My code is causing a NullReferenceEx ception. Can anyone find out what is the problem please?
------------------------------------ Code: ---------------------------------------------------- <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" AutoEventWireup ="false" Inherits="WebAp plication2.WebF orm9" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm9 </title> <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> <meta content="C#" name="CODE_LANG UAGE"> <meta content="JavaSc ript" name="vs_defaul tClientScript"> <meta content="http://schemas.microso ft.com/intellisense/ie5" name="vs_target Schema"> </HEAD> <body MS_POSITIONING= "GridLayout "> <form id="Form1" method="post" runat="server"> <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 19px" runat="server" Width="536px" Height="8px"></asp:Label> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 152px" runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" BorderStyle="No ne" BorderWidth="1p x" BackColor="Whit e" CellPadding="4" > <FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle> <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" BackColor="#009 999"></SelectedItemSty le> <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" BackColor="#003 399"></HeaderStyle> <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" BackColor="#99C CCC" Mode="NumericPa ges"></PagerStyle> </asp:DataGrid> <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 16px" runat="server" Width="112px" Height="24px" AutoPostBack="T rue"></asp:DropDownLis t> <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; TOP: 48px" runat="server" Width="272px" Height="16px" ForeColor="Red" >I want to display notes of selected employee</asp:Label> <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server" Width="704px" Height="56px"></asp:Label></form> </body> </HTML>
--------------------------------------------------code behind-------------------------------------------------------------------------- using System; using System.Collecti ons; using System.Componen tModel; using System.Data; using System.Data.Sql Client; using System.Drawing; using System.Web; using System.Web.Sess ionState; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls;
namespace WebApplication2 { /// <summary> /// Summary description for WebForm9. /// </summary> public class WebForm9 : System.Web.UI.P age { protected DataSet ds1 = new DataSet(); protected System.Web.UI.W ebControls.Labe l lblDisplay; protected System.Web.UI.W ebControls.Data Grid DataGrid1; protected System.Web.UI.W ebControls.Labe l lblText; protected System.Web.UI.W ebControls.Labe l lblSpecific; protected System.Web.UI.W ebControls.Drop DownList ddLastName;
private void Page_Load(objec t sender, System.EventArg s e) { if(!Page.IsPost Back) { string connectionStrin g = "data source =localhost; initial catalog =Northwind; integrated security=true;" ; SqlConnection sqlConnection1 = new SqlConnection(c onnectionString );
SqlCommand sqlCommand1 = new SqlCommand(); SqlDataAdapter sda1 = new SqlDataAdapter( );
// "dataset defined at class level" // DataSet ds1 = new DataSet();
sda1.SelectComm and = sqlCommand1; sda1.SelectComm and.Connection = sqlConnection1; sda1.SelectComm and.CommandType = CommandType.Tex t; sda1.SelectComm and.CommandText = "select * from Employees";
sda1.Fill(ds1," Employees");
SqlDataAdapter sda2 = new SqlDataAdapter( );
sda2.SelectComm and = sqlCommand1; sda2.SelectComm and.Connection = sqlConnection1; sda2.SelectComm and.CommandType = CommandType.Tex t; sda2.SelectComm and.CommandText = "select * from Customers";
sda2.Fill(ds1," Customers");
ddLastName.Data Source = ds1; ddLastName.Data Member = "Employees" ; ddLastName.Data TextField = "LastName"; ddLastName.Data Bind(); ddLastName.Item s.Insert(0,"Sel ect:");
// to fill with specific cell data lblSpecific.Tex t = "Displaying specific Data:<br><br>"; lblSpecific.Tex t += ds1.Tables["Employees"].Rows[0]["Notes"].ToString();
// to fill the datagrid DataGrid1.DataS ource = ds1; DataGrid1.DataM ember = "Employees" ; DataGrid1.DataB ind();
} }
#region Web Form Designer generated code override protected void OnInit(EventArg s e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeCompo nent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeCompo nent() { this.ddLastName .SelectedIndexC hanged += new System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); this.Load += new System.EventHan dler(this.Page_ Load);
} #endregion
private void ddLastName_Sele ctedIndexChange d(object sender, System.EventArg s e) { if(ddLastName.S electedIndex != 0) { int i = 0; foreach(DataRow r in ds1.Tables["Employees"].Rows) { if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) { lblDisplay.Text = ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); } i++; } } else { lblDisplay.Text = ""; } } } }
You are right. But, please write me more specific coding about caching:
1- code of caching exactly: as I looked at msdn there is difficult things to
set and there is no overloading of Cache.Add() that takes 1 parameter as you
wrote.
2- where exactly to put that caching code?
Thanks.
"Mr Newbie" <he**@now.com > wrote in message
news:uV******** ******@tk2msftn gp13.phx.gbl... The problem is that when you click the Dropdown Box, you trigger a postback. Unfortunately, your Page_Load event only fills the dataset during the initial GET. So there is no data to be had when you do your Autopostback.
Once a Webform is constructed and the page rendered, the object is destroyed. You need to arrange for the data to be filled on the initial get and saved to the cache for example.
cache("ds1)= Ds1
and as an else condition to your if not IsPostback
ds1 = cache("ds1")
page.DataBind() .. . . . .etc
PS: This is a common mistake to make.
HTH "Bishoy George" <bi****@bishoy. com> wrote in message news:uN******** ********@TK2MSF TNGP14.phx.gbl. ..I have a dataset called ds1 filled with 2 tables Employees and Customers from Northwind database. I have dropdownList called ddLastName with the following properties:
ddLastName.Data Source = ds1; ddLastName.Data Member = "Employees" ; ddLastName.Data TextField = "LastName"; ddLastName.Data Bind(); ddLastName.Item s.Insert(0,"Sel ect:");
I have a label called lblDisplay
I want the label to display the Notes column data of the selected item in the dropdownList.
My code is causing a NullReferenceEx ception. Can anyone find out what is the problem please?
------------------------------------ Code: ---------------------------------------------------- <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" AutoEventWireup ="false" Inherits="WebAp plication2.WebF orm9" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm9 </title> <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> <meta content="C#" name="CODE_LANG UAGE"> <meta content="JavaSc ript" name="vs_defaul tClientScript"> <meta content="http://schemas.microso ft.com/intellisense/ie5" name="vs_target Schema"> </HEAD> <body MS_POSITIONING= "GridLayout "> <form id="Form1" method="post" runat="server"> <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 19px" runat="server" Width="536px" Height="8px"></asp:Label> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 152px" runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" BorderStyle="No ne" BorderWidth="1p x" BackColor="Whit e" CellPadding="4" > <FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle> <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" BackColor="#009 999"></SelectedItemSty le> <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" BackColor="#003 399"></HeaderStyle> <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" BackColor="#99C CCC" Mode="NumericPa ges"></PagerStyle> </asp:DataGrid> <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 16px" runat="server" Width="112px" Height="24px" AutoPostBack="T rue"></asp:DropDownLis t> <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; TOP: 48px" runat="server" Width="272px" Height="16px" ForeColor="Red" >I want to display notes of selected employee</asp:Label> <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server" Width="704px" Height="56px"></asp:Label></form> </body> </HTML>
--------------------------------------------------code behind-------------------------------------------------------------------------- using System; using System.Collecti ons; using System.Componen tModel; using System.Data; using System.Data.Sql Client; using System.Drawing; using System.Web; using System.Web.Sess ionState; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls;
namespace WebApplication2 { /// <summary> /// Summary description for WebForm9. /// </summary> public class WebForm9 : System.Web.UI.P age { protected DataSet ds1 = new DataSet(); protected System.Web.UI.W ebControls.Labe l lblDisplay; protected System.Web.UI.W ebControls.Data Grid DataGrid1; protected System.Web.UI.W ebControls.Labe l lblText; protected System.Web.UI.W ebControls.Labe l lblSpecific; protected System.Web.UI.W ebControls.Drop DownList ddLastName;
private void Page_Load(objec t sender, System.EventArg s e) { if(!Page.IsPost Back) { string connectionStrin g = "data source =localhost; initial catalog =Northwind; integrated security=true;" ; SqlConnection sqlConnection1 = new SqlConnection(c onnectionString );
SqlCommand sqlCommand1 = new SqlCommand(); SqlDataAdapter sda1 = new SqlDataAdapter( );
// "dataset defined at class level" // DataSet ds1 = new DataSet();
sda1.SelectComm and = sqlCommand1; sda1.SelectComm and.Connection = sqlConnection1; sda1.SelectComm and.CommandType = CommandType.Tex t; sda1.SelectComm and.CommandText = "select * from Employees";
sda1.Fill(ds1," Employees");
SqlDataAdapter sda2 = new SqlDataAdapter( );
sda2.SelectComm and = sqlCommand1; sda2.SelectComm and.Connection = sqlConnection1; sda2.SelectComm and.CommandType = CommandType.Tex t; sda2.SelectComm and.CommandText = "select * from Customers";
sda2.Fill(ds1," Customers");
ddLastName.Data Source = ds1; ddLastName.Data Member = "Employees" ; ddLastName.Data TextField = "LastName"; ddLastName.Data Bind(); ddLastName.Item s.Insert(0,"Sel ect:");
// to fill with specific cell data lblSpecific.Tex t = "Displaying specific Data:<br><br>"; lblSpecific.Tex t += ds1.Tables["Employees"].Rows[0]["Notes"].ToString();
// to fill the datagrid DataGrid1.DataS ource = ds1; DataGrid1.DataM ember = "Employees" ; DataGrid1.DataB ind();
} }
#region Web Form Designer generated code override protected void OnInit(EventArg s e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeCompo nent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeCompo nent() { this.ddLastName .SelectedIndexC hanged += new System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); this.Load += new System.EventHan dler(this.Page_ Load);
} #endregion
private void ddLastName_Sele ctedIndexChange d(object sender, System.EventArg s e) { if(ddLastName.S electedIndex != 0) { int i = 0; foreach(DataRow r in ds1.Tables["Employees"].Rows) { if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) { lblDisplay.Text = ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); } i++; } } else { lblDisplay.Text = ""; } } } }
Here's a little example which uses a helper function. And yes your right
about the constructor but that was not meant to be tested code just really
to point you in the right direction. In this example, the form is simply a
main switchboard which does not use any data, on the other forms in the
application they define the dataset, and adapter as class level variables
and load them from cache in the Page_Load event as described which can be
done with a simple assignment variableName=ca che("storedIden tifier").
Hope this helps you.
Regards - Mr N. . . .
----------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.adaptCalls.F ill(Me.DsCalls1 )
Me.adaptContact s.Fill(Me.DsCon tacts1)
Me.adaptContact Types.Fill(Me.D sContactTypes1)
AddToCache("ada ptCalls", adaptCalls)
AddToCache("ada ptContacts", adaptContacts)
AddToCache("ada ptContactTypes" , adaptContactTyp es)
AddToCache("dsC alls", DsCalls1)
AddToCache("dsC ontacts", DsContacts1)
AddToCache("dsC ontactTypes", DsContactTypes1 )
End If
End Sub
Private Sub AddToCache(ByVa l name As String, ByVal item As Object)
If Not IsNothing(Cache (name)) Then
Return
Else
Cache.Add(name, item, Nothing, DateTime.MaxVal ue,
System.TimeSpan .FromDays(20), Caching.CacheIt emPriority.Defa ult, Nothing)
End If
End Sub
"Bishoy George" <bi****@bishoy. com> wrote in message
news:ul******** ******@TK2MSFTN GP11.phx.gbl... You are right. But, please write me more specific coding about caching: 1- code of caching exactly: as I looked at msdn there is difficult things to set and there is no overloading of Cache.Add() that takes 1 parameter as you wrote. 2- where exactly to put that caching code? Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:uV******** ******@tk2msftn gp13.phx.gbl... The problem is that when you click the Dropdown Box, you trigger a postback. Unfortunately, your Page_Load event only fills the dataset during the initial GET. So there is no data to be had when you do your Autopostback.
Once a Webform is constructed and the page rendered, the object is destroyed. You need to arrange for the data to be filled on the initial get and saved to the cache for example.
cache("ds1)= Ds1
and as an else condition to your if not IsPostback
ds1 = cache("ds1")
page.DataBind() .. . . . .etc
PS: This is a common mistake to make.
HTH "Bishoy George" <bi****@bishoy. com> wrote in message news:uN******** ********@TK2MSF TNGP14.phx.gbl. ..I have a dataset called ds1 filled with 2 tables Employees and Customers from Northwind database. I have dropdownList called ddLastName with the following properties:
ddLastName.Data Source = ds1; ddLastName.Data Member = "Employees" ; ddLastName.Data TextField = "LastName"; ddLastName.Data Bind(); ddLastName.Item s.Insert(0,"Sel ect:");
I have a label called lblDisplay
I want the label to display the Notes column data of the selected item in the dropdownList.
My code is causing a NullReferenceEx ception. Can anyone find out what is the problem please?
------------------------------------ Code: ---------------------------------------------------- <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" AutoEventWireup ="false" Inherits="WebAp plication2.WebF orm9" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm9 </title> <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> <meta content="C#" name="CODE_LANG UAGE"> <meta content="JavaSc ript" name="vs_defaul tClientScript"> <meta content="http://schemas.microso ft.com/intellisense/ie5" name="vs_target Schema"> </HEAD> <body MS_POSITIONING= "GridLayout "> <form id="Form1" method="post" runat="server"> <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 19px" runat="server" Width="536px" Height="8px"></asp:Label> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 152px" runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" BorderStyle="No ne" BorderWidth="1p x" BackColor="Whit e" CellPadding="4" > <FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle> <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" BackColor="#009 999"></SelectedItemSty le> <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" BackColor="#003 399"></HeaderStyle> <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" BackColor="#99C CCC" Mode="NumericPa ges"></PagerStyle> </asp:DataGrid> <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 16px" runat="server" Width="112px" Height="24px" AutoPostBack="T rue"></asp:DropDownLis t> <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; TOP: 48px" runat="server" Width="272px" Height="16px" ForeColor="Red" >I want to display notes of selected employee</asp:Label> <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server" Width="704px" Height="56px"></asp:Label></form> </body> </HTML>
--------------------------------------------------code behind-------------------------------------------------------------------------- using System; using System.Collecti ons; using System.Componen tModel; using System.Data; using System.Data.Sql Client; using System.Drawing; using System.Web; using System.Web.Sess ionState; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls;
namespace WebApplication2 { /// <summary> /// Summary description for WebForm9. /// </summary> public class WebForm9 : System.Web.UI.P age { protected DataSet ds1 = new DataSet(); protected System.Web.UI.W ebControls.Labe l lblDisplay; protected System.Web.UI.W ebControls.Data Grid DataGrid1; protected System.Web.UI.W ebControls.Labe l lblText; protected System.Web.UI.W ebControls.Labe l lblSpecific; protected System.Web.UI.W ebControls.Drop DownList ddLastName;
private void Page_Load(objec t sender, System.EventArg s e) { if(!Page.IsPost Back) { string connectionStrin g = "data source =localhost; initial catalog =Northwind; integrated security=true;" ; SqlConnection sqlConnection1 = new SqlConnection(c onnectionString );
SqlCommand sqlCommand1 = new SqlCommand(); SqlDataAdapter sda1 = new SqlDataAdapter( );
// "dataset defined at class level" // DataSet ds1 = new DataSet();
sda1.SelectComm and = sqlCommand1; sda1.SelectComm and.Connection = sqlConnection1; sda1.SelectComm and.CommandType = CommandType.Tex t; sda1.SelectComm and.CommandText = "select * from Employees";
sda1.Fill(ds1," Employees");
SqlDataAdapter sda2 = new SqlDataAdapter( );
sda2.SelectComm and = sqlCommand1; sda2.SelectComm and.Connection = sqlConnection1; sda2.SelectComm and.CommandType = CommandType.Tex t; sda2.SelectComm and.CommandText = "select * from Customers";
sda2.Fill(ds1," Customers");
ddLastName.Data Source = ds1; ddLastName.Data Member = "Employees" ; ddLastName.Data TextField = "LastName"; ddLastName.Data Bind(); ddLastName.Item s.Insert(0,"Sel ect:");
// to fill with specific cell data lblSpecific.Tex t = "Displaying specific Data:<br><br>"; lblSpecific.Tex t += ds1.Tables["Employees"].Rows[0]["Notes"].ToString();
// to fill the datagrid DataGrid1.DataS ource = ds1; DataGrid1.DataM ember = "Employees" ; DataGrid1.DataB ind();
} }
#region Web Form Designer generated code override protected void OnInit(EventArg s e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeCompo nent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeCompo nent() { this.ddLastName .SelectedIndexC hanged += new System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); this.Load += new System.EventHan dler(this.Page_ Load);
} #endregion
private void ddLastName_Sele ctedIndexChange d(object sender, System.EventArg s e) { if(ddLastName.S electedIndex != 0) { int i = 0; foreach(DataRow r in ds1.Tables["Employees"].Rows) { if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) { lblDisplay.Text = ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); } i++; } } else { lblDisplay.Text = ""; } } } }
I am very disturbing, but if you please could you write it again in C#
because I don't understand vb.net.
Many Thanks.
"Mr Newbie" <he**@now.com > wrote in message
news:eH******** ******@TK2MSFTN GP14.phx.gbl... Here's a little example which uses a helper function. And yes your right about the constructor but that was not meant to be tested code just really to point you in the right direction. In this example, the form is simply a main switchboard which does not use any data, on the other forms in the application they define the dataset, and adapter as class level variables and load them from cache in the Page_Load event as described which can be done with a simple assignment variableName=ca che("storedIden tifier").
Hope this helps you.
Regards - Mr N. . . .
----------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load 'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.adaptCalls.F ill(Me.DsCalls1 ) Me.adaptContact s.Fill(Me.DsCon tacts1) Me.adaptContact Types.Fill(Me.D sContactTypes1)
AddToCache("ada ptCalls", adaptCalls) AddToCache("ada ptContacts", adaptContacts) AddToCache("ada ptContactTypes" , adaptContactTyp es)
AddToCache("dsC alls", DsCalls1) AddToCache("dsC ontacts", DsContacts1) AddToCache("dsC ontactTypes", DsContactTypes1 )
End If
End Sub
Private Sub AddToCache(ByVa l name As String, ByVal item As Object) If Not IsNothing(Cache (name)) Then Return Else Cache.Add(name, item, Nothing, DateTime.MaxVal ue, System.TimeSpan .FromDays(20), Caching.CacheIt emPriority.Defa ult, Nothing) End If End Sub "Bishoy George" <bi****@bishoy. com> wrote in message news:ul******** ******@TK2MSFTN GP11.phx.gbl... You are right. But, please write me more specific coding about caching: 1- code of caching exactly: as I looked at msdn there is difficult things to set and there is no overloading of Cache.Add() that takes 1 parameter as you wrote. 2- where exactly to put that caching code? Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:uV******** ******@tk2msftn gp13.phx.gbl... The problem is that when you click the Dropdown Box, you trigger a postback. Unfortunately, your Page_Load event only fills the dataset during the initial GET. So there is no data to be had when you do your Autopostback.
Once a Webform is constructed and the page rendered, the object is destroyed. You need to arrange for the data to be filled on the initial get and saved to the cache for example.
cache("ds1)= Ds1
and as an else condition to your if not IsPostback
ds1 = cache("ds1")
page.DataBind() .. . . . .etc
PS: This is a common mistake to make.
HTH "Bishoy George" <bi****@bishoy. com> wrote in message news:uN******** ********@TK2MSF TNGP14.phx.gbl. .. I have a dataset called ds1 filled with 2 tables Employees and Customers from Northwind database. I have dropdownList called ddLastName with the following properties:
ddLastName.Data Source = ds1; ddLastName.Data Member = "Employees" ; ddLastName.Data TextField = "LastName"; ddLastName.Data Bind(); ddLastName.Item s.Insert(0,"Sel ect:");
I have a label called lblDisplay
I want the label to display the Notes column data of the selected item in the dropdownList.
My code is causing a NullReferenceEx ception. Can anyone find out what is the problem please?
------------------------------------ Code: ---------------------------------------------------- <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" AutoEventWireup ="false" Inherits="WebAp plication2.WebF orm9" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm9 </title> <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> <meta content="C#" name="CODE_LANG UAGE"> <meta content="JavaSc ript" name="vs_defaul tClientScript"> <meta content="http://schemas.microso ft.com/intellisense/ie5" name="vs_target Schema"> </HEAD> <body MS_POSITIONING= "GridLayout "> <form id="Form1" method="post" runat="server"> <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 19px" runat="server" Width="536px" Height="8px"></asp:Label> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 152px" runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" BorderStyle="No ne" BorderWidth="1p x" BackColor="Whit e" CellPadding="4" > <FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle> <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" BackColor="#009 999"></SelectedItemSty le> <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" BackColor="#003 399"></HeaderStyle> <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" BackColor="#99C CCC" Mode="NumericPa ges"></PagerStyle> </asp:DataGrid> <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 16px" runat="server" Width="112px" Height="24px" AutoPostBack="T rue"></asp:DropDownLis t> <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; TOP: 48px" runat="server" Width="272px" Height="16px" ForeColor="Red" >I want to display notes of selected employee</asp:Label> <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server" Width="704px" Height="56px"></asp:Label></form> </body> </HTML>
--------------------------------------------------code behind-------------------------------------------------------------------------- using System; using System.Collecti ons; using System.Componen tModel; using System.Data; using System.Data.Sql Client; using System.Drawing; using System.Web; using System.Web.Sess ionState; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls;
namespace WebApplication2 { /// <summary> /// Summary description for WebForm9. /// </summary> public class WebForm9 : System.Web.UI.P age { protected DataSet ds1 = new DataSet(); protected System.Web.UI.W ebControls.Labe l lblDisplay; protected System.Web.UI.W ebControls.Data Grid DataGrid1; protected System.Web.UI.W ebControls.Labe l lblText; protected System.Web.UI.W ebControls.Labe l lblSpecific; protected System.Web.UI.W ebControls.Drop DownList ddLastName;
private void Page_Load(objec t sender, System.EventArg s e) { if(!Page.IsPost Back) { string connectionStrin g = "data source =localhost; initial catalog =Northwind; integrated security=true;" ; SqlConnection sqlConnection1 = new SqlConnection(c onnectionString );
SqlCommand sqlCommand1 = new SqlCommand(); SqlDataAdapter sda1 = new SqlDataAdapter( );
// "dataset defined at class level" // DataSet ds1 = new DataSet();
sda1.SelectComm and = sqlCommand1; sda1.SelectComm and.Connection = sqlConnection1; sda1.SelectComm and.CommandType = CommandType.Tex t; sda1.SelectComm and.CommandText = "select * from Employees";
sda1.Fill(ds1," Employees");
SqlDataAdapter sda2 = new SqlDataAdapter( );
sda2.SelectComm and = sqlCommand1; sda2.SelectComm and.Connection = sqlConnection1; sda2.SelectComm and.CommandType = CommandType.Tex t; sda2.SelectComm and.CommandText = "select * from Customers";
sda2.Fill(ds1," Customers");
ddLastName.Data Source = ds1; ddLastName.Data Member = "Employees" ; ddLastName.Data TextField = "LastName"; ddLastName.Data Bind(); ddLastName.Item s.Insert(0,"Sel ect:");
// to fill with specific cell data lblSpecific.Tex t = "Displaying specific Data:<br><br>"; lblSpecific.Tex t += ds1.Tables["Employees"].Rows[0]["Notes"].ToString();
// to fill the datagrid DataGrid1.DataS ource = ds1; DataGrid1.DataM ember = "Employees" ; DataGrid1.DataB ind();
} }
#region Web Form Designer generated code override protected void OnInit(EventArg s e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeCompo nent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeCompo nent() { this.ddLastName .SelectedIndexC hanged += new System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); this.Load += new System.EventHan dler(this.Page_ Load);
} #endregion
private void ddLastName_Sele ctedIndexChange d(object sender, System.EventArg s e) { if(ddLastName.S electedIndex != 0) { int i = 0; foreach(DataRow r in ds1.Tables["Employees"].Rows) { if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) { lblDisplay.Text = ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); } i++; } } else { lblDisplay.Text = ""; } } } }
I could, but you hould do some research yourself. This is not rocket science
(only a few simple lines) and there are translators out on the web which
will do this for you if you look.
I don't mean to be tough on you, but you do need to get hold of the
pioneering spirit in order to progress. Twenty years ago, I was working in
an electronics lab fixing some equipment and I was having trouble with one
particular circuit. I asked my boss for help, and his reply was to slap down
hard the manual on my desk and he told me to read it. I was furious at him
and decided never to ask him for help again and then subsequently became an
expert on this particular equipment.
I think his approach was perhaps a bit draconian, however, it made me more
self sufficient than I perhaps would have been had everything been done for
me.
Regards - Mr N . . . .
"Bishoy George" <bi****@bishoy. com> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl... I am very disturbing, but if you please could you write it again in C# because I don't understand vb.net. Many Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:eH******** ******@TK2MSFTN GP14.phx.gbl... Here's a little example which uses a helper function. And yes your right about the constructor but that was not meant to be tested code just really to point you in the right direction. In this example, the form is simply a main switchboard which does not use any data, on the other forms in the application they define the dataset, and adapter as class level variables and load them from cache in the Page_Load event as described which can be done with a simple assignment variableName=ca che("storedIden tifier").
Hope this helps you.
Regards - Mr N. . . .
----------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load 'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.adaptCalls.F ill(Me.DsCalls1 ) Me.adaptContact s.Fill(Me.DsCon tacts1) Me.adaptContact Types.Fill(Me.D sContactTypes1)
AddToCache("ada ptCalls", adaptCalls) AddToCache("ada ptContacts", adaptContacts) AddToCache("ada ptContactTypes" , adaptContactTyp es)
AddToCache("dsC alls", DsCalls1) AddToCache("dsC ontacts", DsContacts1) AddToCache("dsC ontactTypes", DsContactTypes1 )
End If
End Sub
Private Sub AddToCache(ByVa l name As String, ByVal item As Object) If Not IsNothing(Cache (name)) Then Return Else Cache.Add(name, item, Nothing, DateTime.MaxVal ue, System.TimeSpan .FromDays(20), Caching.CacheIt emPriority.Defa ult, Nothing) End If End Sub "Bishoy George" <bi****@bishoy. com> wrote in message news:ul******** ******@TK2MSFTN GP11.phx.gbl... You are right. But, please write me more specific coding about caching: 1- code of caching exactly: as I looked at msdn there is difficult things to set and there is no overloading of Cache.Add() that takes 1 parameter as you wrote. 2- where exactly to put that caching code? Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:uV******** ******@tk2msftn gp13.phx.gbl... The problem is that when you click the Dropdown Box, you trigger a postback. Unfortunately, your Page_Load event only fills the dataset during the initial GET. So there is no data to be had when you do your Autopostback.
Once a Webform is constructed and the page rendered, the object is destroyed. You need to arrange for the data to be filled on the initial get and saved to the cache for example.
cache("ds1)= Ds1
and as an else condition to your if not IsPostback
ds1 = cache("ds1")
page.DataBind() .. . . . .etc
PS: This is a common mistake to make.
HTH "Bishoy George" <bi****@bishoy. com> wrote in message news:uN******** ********@TK2MSF TNGP14.phx.gbl. .. >I have a dataset called ds1 filled with 2 tables Employees and >Customer s from Northwind database. > I have dropdownList called ddLastName with the following properties: > > ddLastName.Data Source = ds1; > ddLastName.Data Member = "Employees" ; > ddLastName.Data TextField = "LastName"; > ddLastName.Data Bind(); > ddLastName.Item s.Insert(0,"Sel ect:"); > > I have a label called lblDisplay > > I want the label to display the Notes column data of the selected item > in the dropdownList. > > My code is causing a NullReferenceEx ception. > Can anyone find out what is the problem please? > > ------------------------------------ > Code: ---------------------------------------------------- > <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" > AutoEventWireup ="false" Inherits="WebAp plication2.WebF orm9" %> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > > <HTML> > <HEAD> > <title>WebForm9 </title> > <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> > <meta content="C#" name="CODE_LANG UAGE"> > <meta content="JavaSc ript" name="vs_defaul tClientScript"> > <meta content="http://schemas.microso ft.com/intellisense/ie5" > name="vs_target Schema"> > </HEAD> > <body MS_POSITIONING= "GridLayout "> > <form id="Form1" method="post" runat="server"> > <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; > POSITION: absolute; TOP: 19px" > runat="server" Width="536px" Height="8px"></asp:Label> > <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; > POSITION: absolute; TOP: 152px" > runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" > BorderStyle="No ne" BorderWidth="1p x" > BackColor="Whit e" CellPadding="4" > > <FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle> > <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" > BackColor="#009 999"></SelectedItemSty le> > <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> > <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" > BackColor="#003 399"></HeaderStyle> > <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" > BackColor="#99C CCC" Mode="NumericPa ges"></PagerStyle> > </asp:DataGrid> > <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; > POSITION: absolute; TOP: 16px" > runat="server" Width="112px" Height="24px" > AutoPostBack="T rue"></asp:DropDownLis t> > <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION: > absolute; TOP: 48px" runat="server" > Width="272px" Height="16px" ForeColor="Red" >I want to display notes > of selected employee</asp:Label> > <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; > POSITION: absolute; TOP: 72px" > runat="server" Width="704px" Height="56px"></asp:Label></form> > </body> > </HTML> > > --------------------------------------------------code > behind-------------------------------------------------------------------------- > using System; > using System.Collecti ons; > using System.Componen tModel; > using System.Data; > using System.Data.Sql Client; > using System.Drawing; > using System.Web; > using System.Web.Sess ionState; > using System.Web.UI; > using System.Web.UI.W ebControls; > using System.Web.UI.H tmlControls; > > namespace WebApplication2 > { > /// <summary> > /// Summary description for WebForm9. > /// </summary> > public class WebForm9 : System.Web.UI.P age > { > protected DataSet ds1 = new DataSet(); > protected System.Web.UI.W ebControls.Labe l lblDisplay; > protected System.Web.UI.W ebControls.Data Grid DataGrid1; > protected System.Web.UI.W ebControls.Labe l lblText; > protected System.Web.UI.W ebControls.Labe l lblSpecific; > protected System.Web.UI.W ebControls.Drop DownList ddLastName; > > private void Page_Load(objec t sender, System.EventArg s e) > { > if(!Page.IsPost Back) > { > string connectionStrin g = "data source =localhost; initial catalog > =Northwind; integrated security=true;" ; > SqlConnection sqlConnection1 = new SqlConnection(c onnectionString ); > > SqlCommand sqlCommand1 = new SqlCommand(); > SqlDataAdapter sda1 = new SqlDataAdapter( ); > > // "dataset defined at class level" > // DataSet ds1 = new DataSet(); > > sda1.SelectComm and = sqlCommand1; > sda1.SelectComm and.Connection = sqlConnection1; > sda1.SelectComm and.CommandType = CommandType.Tex t; > sda1.SelectComm and.CommandText = "select * from Employees"; > > sda1.Fill(ds1," Employees"); > > SqlDataAdapter sda2 = new SqlDataAdapter( ); > > sda2.SelectComm and = sqlCommand1; > sda2.SelectComm and.Connection = sqlConnection1; > sda2.SelectComm and.CommandType = CommandType.Tex t; > sda2.SelectComm and.CommandText = "select * from Customers"; > > sda2.Fill(ds1," Customers"); > > ddLastName.Data Source = ds1; > ddLastName.Data Member = "Employees" ; > ddLastName.Data TextField = "LastName"; > ddLastName.Data Bind(); > ddLastName.Item s.Insert(0,"Sel ect:"); > > // to fill with specific cell data > lblSpecific.Tex t = "Displaying specific Data:<br><br>"; > lblSpecific.Tex t += > ds1.Tables["Employees"].Rows[0]["Notes"].ToString(); > > // to fill the datagrid > DataGrid1.DataS ource = ds1; > DataGrid1.DataM ember = "Employees" ; > DataGrid1.DataB ind(); > > } > } > > #region Web Form Designer generated code > override protected void OnInit(EventArg s e) > { > // > // CODEGEN: This call is required by the ASP.NET Web Form Designer. > // > InitializeCompo nent(); > base.OnInit(e); > } > > /// <summary> > /// Required method for Designer support - do not modify > /// the contents of this method with the code editor. > /// </summary> > private void InitializeCompo nent() > { > this.ddLastName .SelectedIndexC hanged += new > System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); > this.Load += new System.EventHan dler(this.Page_ Load); > > } > #endregion > > private void ddLastName_Sele ctedIndexChange d(object sender, > System.EventArg s e) > { > if(ddLastName.S electedIndex != 0) > { > int i = 0; > foreach(DataRow r in ds1.Tables["Employees"].Rows) > { > if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) > { > lblDisplay.Text = > ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); > } > i++; > } > } > else > { > lblDisplay.Text = ""; > } > } > } > } >
Why don't you use an online conversion utility ? http://www.developerfusion.co.uk/uti...btocsharp.aspx
will convert VB.NET to C# ( and C# to VB.NET ) for you.
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
=============== =============== ========
"Bishoy George" <bi****@bishoy. com> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl... I am very disturbing, but if you please could you write it again in C# because I don't understand vb.net. Many Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:eH******** ******@TK2MSFTN GP14.phx.gbl... Here's a little example which uses a helper function. And yes your right about the constructor but that was not meant to be tested code just really to point you in the right direction. In this example, the form is simply a main switchboard which does not use any data, on the other forms in the application they define the dataset, and adapter as class level variables and load them from cache in the Page_Load event as described which can be done with a simple assignment variableName=ca che("storedIden tifier").
Hope this helps you.
Regards - Mr N. . . .
----------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load 'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.adaptCalls.F ill(Me.DsCalls1 ) Me.adaptContact s.Fill(Me.DsCon tacts1) Me.adaptContact Types.Fill(Me.D sContactTypes1)
AddToCache("ada ptCalls", adaptCalls) AddToCache("ada ptContacts", adaptContacts) AddToCache("ada ptContactTypes" , adaptContactTyp es)
AddToCache("dsC alls", DsCalls1) AddToCache("dsC ontacts", DsContacts1) AddToCache("dsC ontactTypes", DsContactTypes1 )
End If
End Sub
Private Sub AddToCache(ByVa l name As String, ByVal item As Object) If Not IsNothing(Cache (name)) Then Return Else Cache.Add(name, item, Nothing, DateTime.MaxVal ue, System.TimeSpan .FromDays(20), Caching.CacheIt emPriority.Defa ult, Nothing) End If End Sub "Bishoy George" <bi****@bishoy. com> wrote in message news:ul******** ******@TK2MSFTN GP11.phx.gbl... You are right. But, please write me more specific coding about caching: 1- code of caching exactly: as I looked at msdn there is difficult things to set and there is no overloading of Cache.Add() that takes 1 parameter as you wrote. 2- where exactly to put that caching code? Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:uV******** ******@tk2msftn gp13.phx.gbl... The problem is that when you click the Dropdown Box, you trigger a postback. Unfortunately, your Page_Load event only fills the dataset during the initial GET. So there is no data to be had when you do your Autopostback.
Once a Webform is constructed and the page rendered, the object is destroyed. You need to arrange for the data to be filled on the initial get and saved to the cache for example.
cache("ds1)= Ds1
and as an else condition to your if not IsPostback
ds1 = cache("ds1")
page.DataBind() .. . . . .etc
PS: This is a common mistake to make.
HTH "Bishoy George" <bi****@bishoy. com> wrote in message news:uN******** ********@TK2MSF TNGP14.phx.gbl. .. >I have a dataset called ds1 filled with 2 tables Employees and Customers from >Northwin d database. > I have dropdownList called ddLastName with the following properties: > > ddLastName.Data Source = ds1; > ddLastName.Data Member = "Employees" ; > ddLastName.Data TextField = "LastName"; > ddLastName.Data Bind(); > ddLastName.Item s.Insert(0,"Sel ect:"); > > I have a label called lblDisplay > > I want the label to display the Notes column data of the selected item in the > dropdownList. > > My code is causing a NullReferenceEx ception. > Can anyone find out what is the problem please? > > ------------------------------------ > Code: ---------------------------------------------------- > <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" AutoEventWireup ="false" > Inherits="WebAp plication2.WebF orm9" %> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > > <HTML> > <HEAD> > <title>WebForm9 </title> > <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> > <meta content="C#" name="CODE_LANG UAGE"> > <meta content="JavaSc ript" name="vs_defaul tClientScript"> > <meta content="http://schemas.microso ft.com/intellisense/ie5" > name="vs_target Schema"> > </HEAD> > <body MS_POSITIONING= "GridLayout "> > <form id="Form1" method="post" runat="server"> > <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; > TOP: 19px" > runat="server" Width="536px" Height="8px"></asp:Label> > <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; > TOP: 152px" > runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" > BorderStyle="No ne" BorderWidth="1p x" > BackColor="Whit e" CellPadding="4" > > <FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle> > <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" > BackColor="#009 999"></SelectedItemSty le> > <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> > <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" > BackColor="#003 399"></HeaderStyle> > <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" BackColor="#99C CCC" > Mode="NumericPa ges"></PagerStyle> > </asp:DataGrid> > <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; POSITION: > absolute; TOP: 16px" > runat="server" Width="112px" Height="24px" > AutoPostBack="T rue"></asp:DropDownLis t> > <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; TOP: > 48px" runat="server" > Width="272px" Height="16px" ForeColor="Red" >I want to display notes of selected > employee</asp:Label> > <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; POSITION: absolute; > TOP: 72px" > runat="server" Width="704px" Height="56px"></asp:Label></form> > </body> > </HTML> > > --------------------------------------------------code > behind-------------------------------------------------------------------------- > using System; > using System.Collecti ons; > using System.Componen tModel; > using System.Data; > using System.Data.Sql Client; > using System.Drawing; > using System.Web; > using System.Web.Sess ionState; > using System.Web.UI; > using System.Web.UI.W ebControls; > using System.Web.UI.H tmlControls; > > namespace WebApplication2 > { > /// <summary> > /// Summary description for WebForm9. > /// </summary> > public class WebForm9 : System.Web.UI.P age > { > protected DataSet ds1 = new DataSet(); > protected System.Web.UI.W ebControls.Labe l lblDisplay; > protected System.Web.UI.W ebControls.Data Grid DataGrid1; > protected System.Web.UI.W ebControls.Labe l lblText; > protected System.Web.UI.W ebControls.Labe l lblSpecific; > protected System.Web.UI.W ebControls.Drop DownList ddLastName; > > private void Page_Load(objec t sender, System.EventArg s e) > { > if(!Page.IsPost Back) > { > string connectionStrin g = "data source =localhost; initial catalog =Northwind; > integrated security=true;" ; > SqlConnection sqlConnection1 = new SqlConnection(c onnectionString ); > > SqlCommand sqlCommand1 = new SqlCommand(); > SqlDataAdapter sda1 = new SqlDataAdapter( ); > > // "dataset defined at class level" > // DataSet ds1 = new DataSet(); > > sda1.SelectComm and = sqlCommand1; > sda1.SelectComm and.Connection = sqlConnection1; > sda1.SelectComm and.CommandType = CommandType.Tex t; > sda1.SelectComm and.CommandText = "select * from Employees"; > > sda1.Fill(ds1," Employees"); > > SqlDataAdapter sda2 = new SqlDataAdapter( ); > > sda2.SelectComm and = sqlCommand1; > sda2.SelectComm and.Connection = sqlConnection1; > sda2.SelectComm and.CommandType = CommandType.Tex t; > sda2.SelectComm and.CommandText = "select * from Customers"; > > sda2.Fill(ds1," Customers"); > > ddLastName.Data Source = ds1; > ddLastName.Data Member = "Employees" ; > ddLastName.Data TextField = "LastName"; > ddLastName.Data Bind(); > ddLastName.Item s.Insert(0,"Sel ect:"); > > // to fill with specific cell data > lblSpecific.Tex t = "Displaying specific Data:<br><br>"; > lblSpecific.Tex t += ds1.Tables["Employees"].Rows[0]["Notes"].ToString(); > > // to fill the datagrid > DataGrid1.DataS ource = ds1; > DataGrid1.DataM ember = "Employees" ; > DataGrid1.DataB ind(); > > } > } > > #region Web Form Designer generated code > override protected void OnInit(EventArg s e) > { > // > // CODEGEN: This call is required by the ASP.NET Web Form Designer. > // > InitializeCompo nent(); > base.OnInit(e); > } > > /// <summary> > /// Required method for Designer support - do not modify > /// the contents of this method with the code editor. > /// </summary> > private void InitializeCompo nent() > { > this.ddLastName .SelectedIndexC hanged += new > System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); > this.Load += new System.EventHan dler(this.Page_ Load); > > } > #endregion > > private void ddLastName_Sele ctedIndexChange d(object sender, System.EventArg s e) > { > if(ddLastName.S electedIndex != 0) > { > int i = 0; > foreach(DataRow r in ds1.Tables["Employees"].Rows) > { > if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) > { > lblDisplay.Text = ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); > } > i++; > } > } > else > { > lblDisplay.Text = ""; > } > } > } > } >
Many thanks Juan for this utility for conversion.
Mr.Newbie:
your code has errors so I can't understand it or even convert it. Still,
thank you.
"Juan T. Llibre" <no***********@ nowhere.com> wrote in message
news:ek******** ******@TK2MSFTN GP14.phx.gbl... Why don't you use an online conversion utility ?
http://www.developerfusion.co.uk/uti...btocsharp.aspx
will convert VB.NET to C# ( and C# to VB.NET ) for you. Juan T. Llibre, ASP.NET MVP ASP.NET FAQ : http://asp.net.do/faq/ Foros de ASP.NET en Español : http://asp.net.do/foros/ =============== =============== ======== "Bishoy George" <bi****@bishoy. com> wrote in message news:eR******** ******@TK2MSFTN GP09.phx.gbl...I am very disturbing, but if you please could you write it again in C# because I don't understand vb.net. Many Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:eH******** ******@TK2MSFTN GP14.phx.gbl... Here's a little example which uses a helper function. And yes your right about the constructor but that was not meant to be tested code just really to point you in the right direction. In this example, the form is simply a main switchboard which does not use any data, on the other forms in the application they define the dataset, and adapter as class level variables and load them from cache in the Page_Load event as described which can be done with a simple assignment variableName=ca che("storedIden tifier").
Hope this helps you.
Regards - Mr N. . . .
----------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load 'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.adaptCalls.F ill(Me.DsCalls1 ) Me.adaptContact s.Fill(Me.DsCon tacts1) Me.adaptContact Types.Fill(Me.D sContactTypes1)
AddToCache("ada ptCalls", adaptCalls) AddToCache("ada ptContacts", adaptContacts) AddToCache("ada ptContactTypes" , adaptContactTyp es)
AddToCache("dsC alls", DsCalls1) AddToCache("dsC ontacts", DsContacts1) AddToCache("dsC ontactTypes", DsContactTypes1 )
End If
End Sub
Private Sub AddToCache(ByVa l name As String, ByVal item As Object) If Not IsNothing(Cache (name)) Then Return Else Cache.Add(name, item, Nothing, DateTime.MaxVal ue, System.TimeSpan .FromDays(20), Caching.CacheIt emPriority.Defa ult, Nothing) End If End Sub "Bishoy George" <bi****@bishoy. com> wrote in message news:ul******** ******@TK2MSFTN GP11.phx.gbl... You are right. But, please write me more specific coding about caching: 1- code of caching exactly: as I looked at msdn there is difficult things to set and there is no overloading of Cache.Add() that takes 1 parameter as you wrote. 2- where exactly to put that caching code? Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:uV******** ******@tk2msftn gp13.phx.gbl... > The problem is that when you click the Dropdown Box, you trigger a > postback. Unfortunately, your Page_Load event only fills the dataset > during the initial GET. So there is no data to be had when you do your > Autopostback. > > Once a Webform is constructed and the page rendered, the object is > destroyed. You need to arrange for the data to be filled on the > initial get and saved to the cache for example. > > cache("ds1)= Ds1 > > > and as an else condition to your if not IsPostback > > ds1 = cache("ds1") > > page.DataBind() .. . . . .etc > > PS: This is a common mistake to make. > > HTH > > > > "Bishoy George" <bi****@bishoy. com> wrote in message > news:uN******** ********@TK2MSF TNGP14.phx.gbl. .. >>I have a dataset called ds1 filled with 2 tables Employees and >>Custome rs from Northwind database. >> I have dropdownList called ddLastName with the following properties: >> >> ddLastName.Data Source = ds1; >> ddLastName.Data Member = "Employees" ; >> ddLastName.Data TextField = "LastName"; >> ddLastName.Data Bind(); >> ddLastName.Item s.Insert(0,"Sel ect:"); >> >> I have a label called lblDisplay >> >> I want the label to display the Notes column data of the selected >> item in the dropdownList. >> >> My code is causing a NullReferenceEx ception. >> Can anyone find out what is the problem please? >> >> ------------------------------------ >> Code: ---------------------------------------------------- >> <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" >> AutoEventWireup ="false" Inherits="WebAp plication2.WebF orm9" %> >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > >> <HTML> >> <HEAD> >> <title>WebForm9 </title> >> <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> >> <meta content="C#" name="CODE_LANG UAGE"> >> <meta content="JavaSc ript" name="vs_defaul tClientScript"> >> <meta content="http://schemas.microso ft.com/intellisense/ie5" >> name="vs_target Schema"> >> </HEAD> >> <body MS_POSITIONING= "GridLayout "> >> <form id="Form1" method="post" runat="server"> >> <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; >> POSITION: absolute; TOP: 19px" >> runat="server" Width="536px" Height="8px"></asp:Label> >> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; >> POSITION: absolute; TOP: 152px" >> runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" >> BorderStyle="No ne" BorderWidth="1p x" >> BackColor="Whit e" CellPadding="4" > >> <FooterStyle ForeColor="#003 399" >> BackColor="#99C CCC"></FooterStyle> >> <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" >> BackColor="#009 999"></SelectedItemSty le> >> <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> >> <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" >> BackColor="#003 399"></HeaderStyle> >> <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" >> BackColor="#99C CCC" Mode="NumericPa ges"></PagerStyle> >> </asp:DataGrid> >> <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; >> POSITION: absolute; TOP: 16px" >> runat="server" Width="112px" Height="24px" >> AutoPostBack="T rue"></asp:DropDownLis t> >> <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION: >> absolute; TOP: 48px" runat="server" >> Width="272px" Height="16px" ForeColor="Red" >I want to display >> notes of selected employee</asp:Label> >> <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; >> POSITION: absolute; TOP: 72px" >> runat="server" Width="704px" Height="56px"></asp:Label></form> >> </body> >> </HTML> >> >> --------------------------------------------------code >> behind-------------------------------------------------------------------------- >> using System; >> using System.Collecti ons; >> using System.Componen tModel; >> using System.Data; >> using System.Data.Sql Client; >> using System.Drawing; >> using System.Web; >> using System.Web.Sess ionState; >> using System.Web.UI; >> using System.Web.UI.W ebControls; >> using System.Web.UI.H tmlControls; >> >> namespace WebApplication2 >> { >> /// <summary> >> /// Summary description for WebForm9. >> /// </summary> >> public class WebForm9 : System.Web.UI.P age >> { >> protected DataSet ds1 = new DataSet(); >> protected System.Web.UI.W ebControls.Labe l lblDisplay; >> protected System.Web.UI.W ebControls.Data Grid DataGrid1; >> protected System.Web.UI.W ebControls.Labe l lblText; >> protected System.Web.UI.W ebControls.Labe l lblSpecific; >> protected System.Web.UI.W ebControls.Drop DownList ddLastName; >> >> private void Page_Load(objec t sender, System.EventArg s e) >> { >> if(!Page.IsPost Back) >> { >> string connectionStrin g = "data source =localhost; initial catalog >> =Northwind; integrated security=true;" ; >> SqlConnection sqlConnection1 = new >> SqlConnection(c onnectionString ); >> >> SqlCommand sqlCommand1 = new SqlCommand(); >> SqlDataAdapter sda1 = new SqlDataAdapter( ); >> >> // "dataset defined at class level" >> // DataSet ds1 = new DataSet(); >> >> sda1.SelectComm and = sqlCommand1; >> sda1.SelectComm and.Connection = sqlConnection1; >> sda1.SelectComm and.CommandType = CommandType.Tex t; >> sda1.SelectComm and.CommandText = "select * from Employees"; >> >> sda1.Fill(ds1," Employees"); >> >> SqlDataAdapter sda2 = new SqlDataAdapter( ); >> >> sda2.SelectComm and = sqlCommand1; >> sda2.SelectComm and.Connection = sqlConnection1; >> sda2.SelectComm and.CommandType = CommandType.Tex t; >> sda2.SelectComm and.CommandText = "select * from Customers"; >> >> sda2.Fill(ds1," Customers"); >> >> ddLastName.Data Source = ds1; >> ddLastName.Data Member = "Employees" ; >> ddLastName.Data TextField = "LastName"; >> ddLastName.Data Bind(); >> ddLastName.Item s.Insert(0,"Sel ect:"); >> >> // to fill with specific cell data >> lblSpecific.Tex t = "Displaying specific Data:<br><br>"; >> lblSpecific.Tex t += >> ds1.Tables["Employees"].Rows[0]["Notes"].ToString(); >> >> // to fill the datagrid >> DataGrid1.DataS ource = ds1; >> DataGrid1.DataM ember = "Employees" ; >> DataGrid1.DataB ind(); >> >> } >> } >> >> #region Web Form Designer generated code >> override protected void OnInit(EventArg s e) >> { >> // >> // CODEGEN: This call is required by the ASP.NET Web Form Designer. >> // >> InitializeCompo nent(); >> base.OnInit(e); >> } >> >> /// <summary> >> /// Required method for Designer support - do not modify >> /// the contents of this method with the code editor. >> /// </summary> >> private void InitializeCompo nent() >> { >> this.ddLastName .SelectedIndexC hanged += new >> System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); >> this.Load += new System.EventHan dler(this.Page_ Load); >> >> } >> #endregion >> >> private void ddLastName_Sele ctedIndexChange d(object sender, >> System.EventArg s e) >> { >> if(ddLastName.S electedIndex != 0) >> { >> int i = 0; >> foreach(DataRow r in ds1.Tables["Employees"].Rows) >> { >> if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) >> { >> lblDisplay.Text = >> ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); >> } >> i++; >> } >> } >> else >> { >> lblDisplay.Text = ""; >> } >> } >> } >> } >> > >
re: Many thanks Juan for this utility for conversion.
You're very welcome.
re: Mr.Newbie: your code has errors
Actually, it doesn't.
You have to work around the limitations of the conversion tool,
by making sure you insert code-line breaks ( the underscore in VB.NET )
so that the conversion utility doesn't think the code statements are truncated.
So, if you insert underscores at the end of the longest lines,
the conversion tool can understand them.
For example, here's an appropiately marked source segment :
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.adaptCalls.F ill(Me.DsCalls1 )
Me.adaptContact s.Fill(Me.DsCon tacts1)
Me.adaptContact Types.Fill(Me.D sContactTypes1)
AddToCache("ada ptCalls", adaptCalls)
AddToCache("ada ptContacts", adaptContacts)
AddToCache("ada ptContactTypes" , adaptContactTyp es)
AddToCache("dsC alls", DsCalls1)
AddToCache("dsC ontacts", DsContacts1)
AddToCache("dsC ontactTypes", DsContactTypes1 )
End If
End Sub
That is correctly converted by the conversion utility to :
private void Page_Load(objec t sender, System.EventArg s e)
{
if (!(Page.IsPostB ack)) {
this.adaptCalls .Fill(this.DsCa lls1);
this.adaptConta cts.Fill(this.D sContacts1);
this.adaptConta ctTypes.Fill(th is.DsContactTyp es1);
AddToCache("ada ptCalls", adaptCalls);
AddToCache("ada ptContacts", adaptContacts);
AddToCache("ada ptContactTypes" , adaptContactTyp es);
AddToCache("dsC alls", DsCalls1);
AddToCache("dsC ontacts", DsContacts1);
AddToCache("dsC ontactTypes", DsContactTypes1 );
}
}
btw, the conversion utility may not do a complete conversion,
or even a completely accurate one, but it sure saves a lot of
typing, since -mostly- checking code for errors is much easier
than writing it.
I'm sure some will disagree on this... ;-)
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
=============== =============== ========
"Bishoy George" <bi****@bishoy. com> wrote in message
news:OM******** ******@TK2MSFTN GP12.phx.gbl... Many thanks Juan for this utility for conversion.
Mr.Newbie: your code has errors so I can't understand it or even convert it. Still, thank you. "Juan T. Llibre" <no***********@ nowhere.com> wrote in message news:ek******** ******@TK2MSFTN GP14.phx.gbl... Why don't you use an online conversion utility ?
http://www.developerfusion.co.uk/uti...btocsharp.aspx
will convert VB.NET to C# ( and C# to VB.NET ) for you. Juan T. Llibre, ASP.NET MVP ASP.NET FAQ : http://asp.net.do/faq/ Foros de ASP.NET en Español : http://asp.net.do/foros/ =============== =============== ======== "Bishoy George" <bi****@bishoy. com> wrote in message news:eR******** ******@TK2MSFTN GP09.phx.gbl...I am very disturbing, but if you please could you write it again in C# because I don't understand vb.net. Many Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:eH******** ******@TK2MSFTN GP14.phx.gbl... Here's a little example which uses a helper function. And yes your right about the constructor but that was not meant to be tested code just really to point you in the right direction. In this example, the form is simply a main switchboard which does not use any data, on the other forms in the application they define the dataset, and adapter as class level variables and load them from cache in the Page_Load event as described which can be done with a simple assignment variableName=ca che("storedIden tifier").
Hope this helps you.
Regards - Mr N. . . .
----------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load 'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.adaptCalls.F ill(Me.DsCalls1 ) Me.adaptContact s.Fill(Me.DsCon tacts1) Me.adaptContact Types.Fill(Me.D sContactTypes1)
AddToCache("ada ptCalls", adaptCalls) AddToCache("ada ptContacts", adaptContacts) AddToCache("ada ptContactTypes" , adaptContactTyp es)
AddToCache("dsC alls", DsCalls1) AddToCache("dsC ontacts", DsContacts1) AddToCache("dsC ontactTypes", DsContactTypes1 )
End If
End Sub
Private Sub AddToCache(ByVa l name As String, ByVal item As Object) If Not IsNothing(Cache (name)) Then Return Else Cache.Add(name, item, Nothing, DateTime.MaxVal ue, System.TimeSpan .FromDays(20), Caching.CacheIt emPriority.Defa ult, Nothing) End If End Sub "Bishoy George" <bi****@bishoy. com> wrote in message news:ul******** ******@TK2MSFTN GP11.phx.gbl... > You are right. But, please write me more specific coding about caching: > 1- code of caching exactly: as I looked at msdn there is difficult things to set and > there is no overloading of Cache.Add() that takes 1 parameter as you wrote. > 2- where exactly to put that caching code? > Thanks. > > "Mr Newbie" <he**@now.com > wrote in message > news:uV******** ******@tk2msftn gp13.phx.gbl... >> The problem is that when you click the Dropdown Box, you trigger a postback. >> Unfortunately, your Page_Load event only fills the dataset during the initial GET. >> So there is no data to be had when you do your Autopostback. >> >> Once a Webform is constructed and the page rendered, the object is destroyed. You >> need to arrange for the data to be filled on the initial get and saved to the cache >> for example. >> >> cache("ds1)= Ds1 >> >> >> and as an else condition to your if not IsPostback >> >> ds1 = cache("ds1") >> >> page.DataBind() .. . . . .etc >> >> PS: This is a common mistake to make. >> >> HTH >> >> >> >> "Bishoy George" <bi****@bishoy. com> wrote in message >> news:uN******** ********@TK2MSF TNGP14.phx.gbl. .. >>>I have a dataset called ds1 filled with 2 tables Employees and Customers from >>>Northwin d database. >>> I have dropdownList called ddLastName with the following properties: >>> >>> ddLastName.Data Source = ds1; >>> ddLastName.Data Member = "Employees" ; >>> ddLastName.Data TextField = "LastName"; >>> ddLastName.Data Bind(); >>> ddLastName.Item s.Insert(0,"Sel ect:"); >>> >>> I have a label called lblDisplay >>> >>> I want the label to display the Notes column data of the selected item in the >>> dropdownList. >>> >>> My code is causing a NullReferenceEx ception. >>> Can anyone find out what is the problem please? >>> >>> ------------------------------------ >>> Code: ---------------------------------------------------- >>> <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" AutoEventWireup ="false" >>> Inherits="WebAp plication2.WebF orm9" %> >>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > >>> <HTML> >>> <HEAD> >>> <title>WebForm9 </title> >>> <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> >>> <meta content="C#" name="CODE_LANG UAGE"> >>> <meta content="JavaSc ript" name="vs_defaul tClientScript"> >>> <meta content="http://schemas.microso ft.com/intellisense/ie5" >>> name="vs_target Schema"> >>> </HEAD> >>> <body MS_POSITIONING= "GridLayout "> >>> <form id="Form1" method="post" runat="server"> >>> <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; >>> TOP: 19px" >>> runat="server" Width="536px" Height="8px"></asp:Label> >>> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; POSITION: >>> absolute; TOP: 152px" >>> runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" >>> BorderStyle="No ne" BorderWidth="1p x" >>> BackColor="Whit e" CellPadding="4" > >>> <FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle> >>> <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" >>> BackColor="#009 999"></SelectedItemSty le> >>> <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> >>> <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" >>> BackColor="#003 399"></HeaderStyle> >>> <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" BackColor="#99C CCC" >>> Mode="NumericPa ges"></PagerStyle> >>> </asp:DataGrid> >>> <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; POSITION: >>> absolute; TOP: 16px" >>> runat="server" Width="112px" Height="24px" >>> AutoPostBack="T rue"></asp:DropDownLis t> >>> <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; >>> TOP: 48px" runat="server" >>> Width="272px" Height="16px" ForeColor="Red" >I want to display notes of selected >>> employee</asp:Label> >>> <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; POSITION: absolute; >>> TOP: 72px" >>> runat="server" Width="704px" Height="56px"></asp:Label></form> >>> </body> >>> </HTML> >>> >>> --------------------------------------------------code >>> behind-------------------------------------------------------------------------- >>> using System; >>> using System.Collecti ons; >>> using System.Componen tModel; >>> using System.Data; >>> using System.Data.Sql Client; >>> using System.Drawing; >>> using System.Web; >>> using System.Web.Sess ionState; >>> using System.Web.UI; >>> using System.Web.UI.W ebControls; >>> using System.Web.UI.H tmlControls; >>> >>> namespace WebApplication2 >>> { >>> /// <summary> >>> /// Summary description for WebForm9. >>> /// </summary> >>> public class WebForm9 : System.Web.UI.P age >>> { >>> protected DataSet ds1 = new DataSet(); >>> protected System.Web.UI.W ebControls.Labe l lblDisplay; >>> protected System.Web.UI.W ebControls.Data Grid DataGrid1; >>> protected System.Web.UI.W ebControls.Labe l lblText; >>> protected System.Web.UI.W ebControls.Labe l lblSpecific; >>> protected System.Web.UI.W ebControls.Drop DownList ddLastName; >>> >>> private void Page_Load(objec t sender, System.EventArg s e) >>> { >>> if(!Page.IsPost Back) >>> { >>> string connectionStrin g = "data source =localhost; initial catalog =Northwind; >>> integrated security=true;" ; >>> SqlConnection sqlConnection1 = new SqlConnection(c onnectionString ); >>> >>> SqlCommand sqlCommand1 = new SqlCommand(); >>> SqlDataAdapter sda1 = new SqlDataAdapter( ); >>> >>> // "dataset defined at class level" >>> // DataSet ds1 = new DataSet(); >>> >>> sda1.SelectComm and = sqlCommand1; >>> sda1.SelectComm and.Connection = sqlConnection1; >>> sda1.SelectComm and.CommandType = CommandType.Tex t; >>> sda1.SelectComm and.CommandText = "select * from Employees"; >>> >>> sda1.Fill(ds1," Employees"); >>> >>> SqlDataAdapter sda2 = new SqlDataAdapter( ); >>> >>> sda2.SelectComm and = sqlCommand1; >>> sda2.SelectComm and.Connection = sqlConnection1; >>> sda2.SelectComm and.CommandType = CommandType.Tex t; >>> sda2.SelectComm and.CommandText = "select * from Customers"; >>> >>> sda2.Fill(ds1," Customers"); >>> >>> ddLastName.Data Source = ds1; >>> ddLastName.Data Member = "Employees" ; >>> ddLastName.Data TextField = "LastName"; >>> ddLastName.Data Bind(); >>> ddLastName.Item s.Insert(0,"Sel ect:"); >>> >>> // to fill with specific cell data >>> lblSpecific.Tex t = "Displaying specific Data:<br><br>"; >>> lblSpecific.Tex t += ds1.Tables["Employees"].Rows[0]["Notes"].ToString(); >>> >>> // to fill the datagrid >>> DataGrid1.DataS ource = ds1; >>> DataGrid1.DataM ember = "Employees" ; >>> DataGrid1.DataB ind(); >>> >>> } >>> } >>> >>> #region Web Form Designer generated code >>> override protected void OnInit(EventArg s e) >>> { >>> // >>> // CODEGEN: This call is required by the ASP.NET Web Form Designer. >>> // >>> InitializeCompo nent(); >>> base.OnInit(e); >>> } >>> >>> /// <summary> >>> /// Required method for Designer support - do not modify >>> /// the contents of this method with the code editor. >>> /// </summary> >>> private void InitializeCompo nent() >>> { >>> this.ddLastName .SelectedIndexC hanged += new >>> System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); >>> this.Load += new System.EventHan dler(this.Page_ Load); >>> >>> } >>> #endregion >>> >>> private void ddLastName_Sele ctedIndexChange d(object sender, System.EventArg s e) >>> { >>> if(ddLastName.S electedIndex != 0) >>> { >>> int i = 0; >>> foreach(DataRow r in ds1.Tables["Employees"].Rows) >>> { >>> if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) >>> { >>> lblDisplay.Text = ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); >>> } >>> i++; >>> } >>> } >>> else >>> { >>> lblDisplay.Text = ""; >>> } >>> } >>> } >>> } >>> >> >> > >
My code does NOT have errors. This is from a working project.
"Bishoy George" <bi****@bishoy. com> wrote in message
news:OM******** ******@TK2MSFTN GP12.phx.gbl... Many thanks Juan for this utility for conversion.
Mr.Newbie: your code has errors so I can't understand it or even convert it. Still, thank you. "Juan T. Llibre" <no***********@ nowhere.com> wrote in message news:ek******** ******@TK2MSFTN GP14.phx.gbl... Why don't you use an online conversion utility ?
http://www.developerfusion.co.uk/uti...btocsharp.aspx
will convert VB.NET to C# ( and C# to VB.NET ) for you. Juan T. Llibre, ASP.NET MVP ASP.NET FAQ : http://asp.net.do/faq/ Foros de ASP.NET en Español : http://asp.net.do/foros/ =============== =============== ======== "Bishoy George" <bi****@bishoy. com> wrote in message news:eR******** ******@TK2MSFTN GP09.phx.gbl...I am very disturbing, but if you please could you write it again in C# because I don't understand vb.net. Many Thanks.
"Mr Newbie" <he**@now.com > wrote in message news:eH******** ******@TK2MSFTN GP14.phx.gbl... Here's a little example which uses a helper function. And yes your right about the constructor but that was not meant to be tested code just really to point you in the right direction. In this example, the form is simply a main switchboard which does not use any data, on the other forms in the application they define the dataset, and adapter as class level variables and load them from cache in the Page_Load event as described which can be done with a simple assignment variableName=ca che("storedIden tifier").
Hope this helps you.
Regards - Mr N. . . .
----------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load 'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.adaptCalls.F ill(Me.DsCalls1 ) Me.adaptContact s.Fill(Me.DsCon tacts1) Me.adaptContact Types.Fill(Me.D sContactTypes1)
AddToCache("ada ptCalls", adaptCalls) AddToCache("ada ptContacts", adaptContacts) AddToCache("ada ptContactTypes" , adaptContactTyp es)
AddToCache("dsC alls", DsCalls1) AddToCache("dsC ontacts", DsContacts1) AddToCache("dsC ontactTypes", DsContactTypes1 )
End If
End Sub
Private Sub AddToCache(ByVa l name As String, ByVal item As Object) If Not IsNothing(Cache (name)) Then Return Else Cache.Add(name, item, Nothing, DateTime.MaxVal ue, System.TimeSpan .FromDays(20), Caching.CacheIt emPriority.Defa ult, Nothing) End If End Sub "Bishoy George" <bi****@bishoy. com> wrote in message news:ul******** ******@TK2MSFTN GP11.phx.gbl... > You are right. But, please write me more specific coding about > caching: > 1- code of caching exactly: as I looked at msdn there is difficult > things to set and there is no overloading of Cache.Add() that takes 1 > parameter as you wrote. > 2- where exactly to put that caching code? > Thanks. > > "Mr Newbie" <he**@now.com > wrote in message > news:uV******** ******@tk2msftn gp13.phx.gbl... >> The problem is that when you click the Dropdown Box, you trigger a >> postback. Unfortunately, your Page_Load event only fills the dataset >> during the initial GET. So there is no data to be had when you do >> your Autopostback. >> >> Once a Webform is constructed and the page rendered, the object is >> destroyed. You need to arrange for the data to be filled on the >> initial get and saved to the cache for example. >> >> cache("ds1)= Ds1 >> >> >> and as an else condition to your if not IsPostback >> >> ds1 = cache("ds1") >> >> page.DataBind() .. . . . .etc >> >> PS: This is a common mistake to make. >> >> HTH >> >> >> >> "Bishoy George" <bi****@bishoy. com> wrote in message >> news:uN******** ********@TK2MSF TNGP14.phx.gbl. .. >>>I have a dataset called ds1 filled with 2 tables Employees and >>>Customer s from Northwind database. >>> I have dropdownList called ddLastName with the following properties: >>> >>> ddLastName.Data Source = ds1; >>> ddLastName.Data Member = "Employees" ; >>> ddLastName.Data TextField = "LastName"; >>> ddLastName.Data Bind(); >>> ddLastName.Item s.Insert(0,"Sel ect:"); >>> >>> I have a label called lblDisplay >>> >>> I want the label to display the Notes column data of the selected >>> item in the dropdownList. >>> >>> My code is causing a NullReferenceEx ception. >>> Can anyone find out what is the problem please? >>> >>> ------------------------------------ >>> Code: ---------------------------------------------------- >>> <%@ Page language="c#" Codebehind="Web Form9.aspx.cs" >>> AutoEventWireup ="false" Inherits="WebAp plication2.WebF orm9" %> >>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > >>> <HTML> >>> <HEAD> >>> <title>WebForm9 </title> >>> <meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR "> >>> <meta content="C#" name="CODE_LANG UAGE"> >>> <meta content="JavaSc ript" name="vs_defaul tClientScript"> >>> <meta content="http://schemas.microso ft.com/intellisense/ie5" >>> name="vs_target Schema"> >>> </HEAD> >>> <body MS_POSITIONING= "GridLayout "> >>> <form id="Form1" method="post" runat="server"> >>> <asp:Label id="lblDisplay " style="Z-INDEX: 101; LEFT: 144px; >>> POSITION: absolute; TOP: 19px" >>> runat="server" Width="536px" Height="8px"></asp:Label> >>> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 24px; >>> POSITION: absolute; TOP: 152px" >>> runat="server" Width="672px" Height="120px" BorderColor="#3 366CC" >>> BorderStyle="No ne" BorderWidth="1p x" >>> BackColor="Whit e" CellPadding="4" > >>> <FooterStyle ForeColor="#003 399" >>> BackColor="#99C CCC"></FooterStyle> >>> <SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" >>> BackColor="#009 999"></SelectedItemSty le> >>> <ItemStyle ForeColor="#003 399" BackColor="Whit e"></ItemStyle> >>> <HeaderStyle Font-Bold="True" ForeColor="#CCC CFF" >>> BackColor="#003 399"></HeaderStyle> >>> <PagerStyle HorizontalAlign ="Left" ForeColor="#003 399" >>> BackColor="#99C CCC" Mode="NumericPa ges"></PagerStyle> >>> </asp:DataGrid> >>> <asp:DropDownLi st id="ddLastName " style="Z-INDEX: 103; LEFT: 16px; >>> POSITION: absolute; TOP: 16px" >>> runat="server" Width="112px" Height="24px" >>> AutoPostBack="T rue"></asp:DropDownLis t> >>> <asp:Label id="lblText" style="Z-INDEX: 104; LEFT: 144px; >>> POSITION: absolute; TOP: 48px" runat="server" >>> Width="272px" Height="16px" ForeColor="Red" >I want to display >>> notes of selected employee</asp:Label> >>> <asp:Label id="lblSpecific " style="Z-INDEX: 105; LEFT: 16px; >>> POSITION: absolute; TOP: 72px" >>> runat="server" Width="704px" Height="56px"></asp:Label></form> >>> </body> >>> </HTML> >>> >>> --------------------------------------------------code >>> behind-------------------------------------------------------------------------- >>> using System; >>> using System.Collecti ons; >>> using System.Componen tModel; >>> using System.Data; >>> using System.Data.Sql Client; >>> using System.Drawing; >>> using System.Web; >>> using System.Web.Sess ionState; >>> using System.Web.UI; >>> using System.Web.UI.W ebControls; >>> using System.Web.UI.H tmlControls; >>> >>> namespace WebApplication2 >>> { >>> /// <summary> >>> /// Summary description for WebForm9. >>> /// </summary> >>> public class WebForm9 : System.Web.UI.P age >>> { >>> protected DataSet ds1 = new DataSet(); >>> protected System.Web.UI.W ebControls.Labe l lblDisplay; >>> protected System.Web.UI.W ebControls.Data Grid DataGrid1; >>> protected System.Web.UI.W ebControls.Labe l lblText; >>> protected System.Web.UI.W ebControls.Labe l lblSpecific; >>> protected System.Web.UI.W ebControls.Drop DownList ddLastName; >>> >>> private void Page_Load(objec t sender, System.EventArg s e) >>> { >>> if(!Page.IsPost Back) >>> { >>> string connectionStrin g = "data source =localhost; initial >>> catalog =Northwind; integrated security=true;" ; >>> SqlConnection sqlConnection1 = new >>> SqlConnection(c onnectionString ); >>> >>> SqlCommand sqlCommand1 = new SqlCommand(); >>> SqlDataAdapter sda1 = new SqlDataAdapter( ); >>> >>> // "dataset defined at class level" >>> // DataSet ds1 = new DataSet(); >>> >>> sda1.SelectComm and = sqlCommand1; >>> sda1.SelectComm and.Connection = sqlConnection1; >>> sda1.SelectComm and.CommandType = CommandType.Tex t; >>> sda1.SelectComm and.CommandText = "select * from Employees"; >>> >>> sda1.Fill(ds1," Employees"); >>> >>> SqlDataAdapter sda2 = new SqlDataAdapter( ); >>> >>> sda2.SelectComm and = sqlCommand1; >>> sda2.SelectComm and.Connection = sqlConnection1; >>> sda2.SelectComm and.CommandType = CommandType.Tex t; >>> sda2.SelectComm and.CommandText = "select * from Customers"; >>> >>> sda2.Fill(ds1," Customers"); >>> >>> ddLastName.Data Source = ds1; >>> ddLastName.Data Member = "Employees" ; >>> ddLastName.Data TextField = "LastName"; >>> ddLastName.Data Bind(); >>> ddLastName.Item s.Insert(0,"Sel ect:"); >>> >>> // to fill with specific cell data >>> lblSpecific.Tex t = "Displaying specific Data:<br><br>"; >>> lblSpecific.Tex t += >>> ds1.Tables["Employees"].Rows[0]["Notes"].ToString(); >>> >>> // to fill the datagrid >>> DataGrid1.DataS ource = ds1; >>> DataGrid1.DataM ember = "Employees" ; >>> DataGrid1.DataB ind(); >>> >>> } >>> } >>> >>> #region Web Form Designer generated code >>> override protected void OnInit(EventArg s e) >>> { >>> // >>> // CODEGEN: This call is required by the ASP.NET Web Form >>> Designer. >>> // >>> InitializeCompo nent(); >>> base.OnInit(e); >>> } >>> >>> /// <summary> >>> /// Required method for Designer support - do not modify >>> /// the contents of this method with the code editor. >>> /// </summary> >>> private void InitializeCompo nent() >>> { >>> this.ddLastName .SelectedIndexC hanged += new >>> System.EventHan dler(this.ddLas tName_SelectedI ndexChanged); >>> this.Load += new System.EventHan dler(this.Page_ Load); >>> >>> } >>> #endregion >>> >>> private void ddLastName_Sele ctedIndexChange d(object sender, >>> System.EventArg s e) >>> { >>> if(ddLastName.S electedIndex != 0) >>> { >>> int i = 0; >>> foreach(DataRow r in ds1.Tables["Employees"].Rows) >>> { >>> if(r["LastName"].ToString() == ddLastName.Sele ctedItem.Text) >>> { >>> lblDisplay.Text = >>> ds1.Tables["Employees"].Rows[i]["Notes"].ToString(); >>> } >>> i++; >>> } >>> } >>> else >>> { >>> lblDisplay.Text = ""; >>> } >>> } >>> } >>> } >>> >> >> > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Simon Harvey |
last post by:
Hi everyone,
I was wondering if it is possible, to use SQL to return more than one table
at a time into a dataset. I only know the basics of SQL and so I'm not sure
if I'm just asking a stupid question. But, I'm not proud! :-)
I'm using Ado.net and I'm wanting to load a DataSet object with several
independent tables. (For those who arent ADO.net programmers, a DataSet can
hold multiple tables and the relationships and contraints...
|
by: JS |
last post by:
I'm trying to create a data layer and having problems returning a DataSet
from my code that's in a class module.
Please forgive me. I'm new to C# (VB'er). I decided to create my data layer
in small steps. Right now, I'm just trying to attach a ComboBox to a dataset
that's in my class module. In the class, I call a Stored Procedure. I know
how to set up the connection, command, adapter, and dataset, what I'm having
a problem with is,...
|
by: Simon Harvey |
last post by:
Hi everyone,
I was wondering if it is possible, to use SQL to return more than one table
at a time into a dataset. I only know the basics of SQL and so I'm not sure
if I'm just asking a stupid question. But, I'm not proud! :-)
I'm using Ado.net and I'm wanting to load a DataSet object with several
independent tables. (For those who arent ADO.net programmers, a DataSet can
hold multiple tables and the relationships and contraints...
|
by: Mike |
last post by:
Hi,
I am trying to solve a problem with a DataSet issue I am having. In my app
the user selects certain options and based on those options it goes out to
the db to get data based on those options. This data will be used in
different Business Objects (Business Rules and Reporting). I have decided
to use DataSets as the data container because the data is dyncamic and will
change based on user selections which I could not simulate in a...
|
by: JIM.H. |
last post by:
Hello,
Can I send a dataset as a parameter into stored procedure and import data to
a table in the stored procedure?
Thanks,
Jim.
| |
by: Jeff Brown |
last post by:
OK i have came to the conclusion that since this app will be run on multiple computers that loading a complete database and then updating on exit is a moot point. I have tried several ideas submitted, but i am unable to get one of them to work completely. Here is the code i had before i realized that when i filled the dataset in the form load procedure that it would "ruin, replace, mess up" the dataset named the same thing on the other form....
|
by: markerussell |
last post by:
I have a question, in that if i have an application is it better to have one dataset per data adapter, ie daCustomerTable -> dsCustomer, daOrders -> dsOrders etc. or to say have a couple of dataset one to hold static information and the other to hold transactional information like orders. Is there a memory overhead having one -> one relationship or having a static and transactional dataset more efficient ?
|
by: Arne |
last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart
from a pocket PC to a webservice.
What is the right datatype?
II have tried dataset as a datatype, but I can't get it to compile.
<WebMethod()> _
Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet
Test program :
Dim cartSet As DataSet
cartSet = ws.VerifySku(cartSet)
|
by: JT |
last post by:
I have an SQL database with one table in it. I want to load the table into
a DataSet, add new records to the DataSet, then commit the changes back to
the database.
Using C#.NET, the following loads the DataSet and fills it:
string SelectString = "SELECT * FROM dbo.Trade";
SqlCommand RecordsSelection = new SqlCommand(SelectString,
ThisConnection);
|
by: Ken Fine |
last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets
and DataTables should be able to answer fairly easily. The basic question is
how I can efficiently match data from one dataset to data in a second
dataset, using a common key. I will first describe the problem in words and
then I will show my code, which has most of the solution done already.
I have built an ASP.NET that queries an Index Server and returns a...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |