Showing posts with label below. Show all posts
Showing posts with label below. Show all posts

Monday, March 26, 2012

System.Net.Mail to address

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.
David
strUser = UtilClass.GetUserName(strUser)
'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "me@dotnet.itags.org.myemail.com"
Const FromAddress As String = "me@dotnet.itags.org.myemail.com"
'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)
'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False
'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)Great Minds must think alike. I just finished this not more than 15
minutes ago. There may be a better way to do it, but I know that this
works.
protected void btnSendUpload_Click(object sender, EventArgs e)
{
string queryString = "Select Email From tblMailer";
string constring = "Data Source=GLSDBS03;Initial
Catalog=CCTS;Persist Security Info=True;User
ID=UserID;Password=Password";
using (SqlConnection connection = new
SqlConnection(constring))
{
connection.Open();
SqlCommand command = new SqlCommand(queryString,
connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string captured = Convert.ToString(reader["EMail"]);
try
{
SmtpClient mailSvr = new SmtpClientYour SMTP
CLient);
MailAddress from = new MailAddress(Your From
Address);
MailAddress to = new MailAddress(captured);
MailMessage msg = new MailMessage(from, to);
msg.Subject = "JACOBS CCTS Labor Upload";
msg.Body = "The attached text file contains Labor
Hours. " + Environment.NewLine + Environment.NewLine;
Attachment attach = new Attachment("\\\\glsdbs03\\d
$\\File\\LaborFile.txt");
msg.Attachments.Add(attach);
mailSvr.Send(msg);
lbStatus.Text = "Labor has been Sent.";
}
catch (Exception ex)
{
lbStatus.Text = ex.Message;
}
}
}
}
I hope this helps
On Nov 21, 4:00 pm, "David C" <dlch...@.lifetimeinc.com> wrote:
> I would like to have an email go to 2 email addresses but when I try it by
> separating with semicolon or comma it fails. Can anyone help? below is m
y
> code (see ToAddress string). Thanks.
> David
> strUser = UtilClass.GetUserName(strUser)
> '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
> Const ToAddress As String = "m...@.myemail.com"
> Const FromAddress As String = "m...@.myemail.com"
> '(1) Create the MailMessage instance
> Dim mm As New System.Net.Mail.MailMessage(ToAddress,
> FromAddress)
> '(2) Assign the MailMessage's properties
> mm.Subject = "Fileroom unhandled exception occurred!"
> mm.Body = "User getting error is " & strUser & vbCrLf & _
> String.Format("An unhandled exception
> occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
> System.Environment.NewLine, ex.Message, ex.StackTrace)
> mm.IsBodyHtml = False
> '(3) Create the SmtpClient object
> Dim smtp As New System.Net.Mail.SmtpClient
> '(4) Send the MailMessage (will use the Web.config setting
s)
> smtp.Send(mm)
in smtp, you write out a header per address, not a comma seperated list. to
support this mailmessage has a To collection, which you add as many addresse
s
as you want:
var mm = new MailMessage(toAddress1,fromAddress);
mm.To.Add(new MailAddress(toAddress2));
-- bruce (sqlwork.com)
"David C" wrote:

> I would like to have an email go to 2 email addresses but when I try it by
> separating with semicolon or comma it fails. Can anyone help? below is m
y
> code (see ToAddress string). Thanks.
> David
> strUser = UtilClass.GetUserName(strUser)
> '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
> Const ToAddress As String = "me@.myemail.com"
> Const FromAddress As String = "me@.myemail.com"
> '(1) Create the MailMessage instance
> Dim mm As New System.Net.Mail.MailMessage(ToAddress,
> FromAddress)
> '(2) Assign the MailMessage's properties
> mm.Subject = "Fileroom unhandled exception occurred!"
> mm.Body = "User getting error is " & strUser & vbCrLf & _
> String.Format("An unhandled exception
> occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
> System.Environment.NewLine, ex.Message, ex.StackTrace)
> mm.IsBodyHtml = False
> '(3) Create the SmtpClient object
> Dim smtp As New System.Net.Mail.SmtpClient
> '(4) Send the MailMessage (will use the Web.config setting
s)
> smtp.Send(mm)
>
>
"David C" <dlchase@.lifetimeinc.com> wrote in message
news:uCJt%23nILIHA.1208@.TK2MSFTNGP03.phx.gbl...

>I would like to have an email go to 2 email addresses but when I try it by
>separating with semicolon or comma it fails.
Well it would do - it's a collection...
http://www.systemnetmail.com/faq/3.2.3.aspx
Mark Rae
ASP.NET MVP
http://www.markrae.net
Perfect. Thanks everyone.
David
"Mark Rae [MVP]" <mark@.markNOSPAMrae.net> wrote in message
news:eHV89AJLIHA.3992@.TK2MSFTNGP03.phx.gbl...
> "David C" <dlchase@.lifetimeinc.com> wrote in message
> news:uCJt%23nILIHA.1208@.TK2MSFTNGP03.phx.gbl...
>
> Well it would do - it's a collection...
> http://www.systemnetmail.com/faq/3.2.3.aspx
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net

System.Net.Mail to address

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.

David
strUser = UtilClass.GetUserName(strUser)

'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "me@dotnet.itags.org.myemail.com"
Const FromAddress As String = "me@dotnet.itags.org.myemail.com"

'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)

'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False

'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient

'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)Great Minds must think alike. I just finished this not more than 15
minutes ago. There may be a better way to do it, but I know that this
works.

protected void btnSendUpload_Click(object sender, EventArgs e)
{
string queryString = "Select Email From tblMailer";
string constring = "Data Source=GLSDBS03;Initial
Catalog=CCTS;Persist Security Info=True;User
ID=UserID;Password=Password";
using (SqlConnection connection = new
SqlConnection(constring))
{
connection.Open();

SqlCommand command = new SqlCommand(queryString,
connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string captured = Convert.ToString(reader["EMail"]);
try
{
SmtpClient mailSvr = new SmtpClientYour SMTP
CLient);
MailAddress from = new MailAddress(Your From
Address);
MailAddress to = new MailAddress(captured);
MailMessage msg = new MailMessage(from, to);
msg.Subject = "JACOBS CCTS Labor Upload";
msg.Body = "The attached text file contains Labor
Hours. " + Environment.NewLine + Environment.NewLine;
Attachment attach = new Attachment("\\\\glsdbs03\\d
$\\File\\LaborFile.txt");
msg.Attachments.Add(attach);
mailSvr.Send(msg);
lbStatus.Text = "Labor has been Sent.";
}
catch (Exception ex)
{
lbStatus.Text = ex.Message;
}
}
}
}

I hope this helps

On Nov 21, 4:00 pm, "David C" <dlch...@.lifetimeinc.comwrote:

Quote:

Originally Posted by

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.
>
David
strUser = UtilClass.GetUserName(strUser)
>
'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "m...@.myemail.com"
Const FromAddress As String = "m...@.myemail.com"
>
'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)
>
'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False
>
'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient
>
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)


in smtp, you write out a header per address, not a comma seperated list. to
support this mailmessage has a To collection, which you add as many addresses
as you want:

var mm = new MailMessage(toAddress1,fromAddress);
mm.To.Add(new MailAddress(toAddress2));

-- bruce (sqlwork.com)

"David C" wrote:

Quote:

Originally Posted by

I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.
>
David
strUser = UtilClass.GetUserName(strUser)
>
'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "me@.myemail.com"
Const FromAddress As String = "me@.myemail.com"
>
'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail.MailMessage(ToAddress,
FromAddress)
>
'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format("An unhandled exception
occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}",
System.Environment.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False
>
'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail.SmtpClient
>
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)
>
>
>


"David C" <dlchase@.lifetimeinc.comwrote in message
news:uCJt%23nILIHA.1208@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>I would like to have an email go to 2 email addresses but when I try it by
>separating with semicolon or comma it fails.


Well it would do - it's a collection...
http://www.systemnetmail.com/faq/3.2.3.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Perfect. Thanks everyone.

David
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message
news:eHV89AJLIHA.3992@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

"David C" <dlchase@.lifetimeinc.comwrote in message
news:uCJt%23nILIHA.1208@.TK2MSFTNGP03.phx.gbl...
>

Quote:

Originally Posted by

>>I would like to have an email go to 2 email addresses but when I try it by
>>separating with semicolon or comma it fails.


>
Well it would do - it's a collection...
http://www.systemnetmail.com/faq/3.2.3.aspx
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Thursday, March 22, 2012

System.NullReferenceException: Object reference not set to an

Hi Ken and thanks for the reply! (My Code below!!!)
What i'm trying to do is a datagrid that has Add,Update,Delete commands.My
Add command is working but my Delete and Update command is giving error :-
System.NullReferenceException: Object reference not set to an instance of an
object.
Refering to the line code:- ItemNumber =
CType(Args.Item.FindControl("ItemNumber"), TextBox).Text
Don't know whats wrong IT WORKS WITH ASP.NETWEBMATRIX!!
But VS.Net give such errors!
Any help Thanks!!
'Option Explicit On
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Public Class datagrid_edit_delete
Inherits System.Web.UI.Page
'Dim ItemTypes As New ArrayList
Protected ItemTypes As New ArrayList
'Protected WithEvents ItemType As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button As System.Web.UI.WebControls.Button
Protected WithEvents PageButtons As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents UpdateMessage As System.Web.UI.WebControls.Label
Protected WithEvents DataGridDisplay As System.Web.UI.WebControls.DataGrid
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
'Dim ItemNumberList As New ArrayList
'Protected WithEvents ItemTypes As System.Web.UI.WebControls.DropDownList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String
Dim PageSize As Integer = 6
'-- Load array ItemNumberList with item numbers
'Dim ItemNumberList = New ArrayList
Dim ItemNumberList = New ArrayList
DBConnection = New
SqlConnection(" server=(local);database=Northwind;integr
ated security=true;")
DBConnection.Open()
SQLString = "SELECT ItemNumber FROM products1 ORDER BY ItemNumber"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
ItemNumberList.Add(DBReader("ItemNumber"))
End While
DBReader.Close()
DBConnection.Close()
ItemNumberList.TrimToSize()
'-- Create Paging Buttons
Dim StartIndex = 0
Dim EndIndex As Integer
Dim StartKey As String
Dim EndKey As String
Dim i As Integer
PageButtons.Controls.Clear()
For i = 1 To Math.Ceiling(ItemNumberList.Count / PageSize)
EndIndex = StartIndex + PageSize - 1
If EndIndex > ItemNumberList.Count - 1 Then
EndIndex = ItemNumberList.Count - 1
End If
StartKey = ItemNumberList(StartIndex)
EndKey = ItemNumberList(EndIndex)
Dim PageButton As Button
PageButton = New Button
PageButton.Text = i
PageButton.ID = "P" & i
PageButton.CommandName = StartKey & "|" & EndKey
PageButton.Style("width") = "20px"
PageButton.Style("background-color") = "#F0F0F0"
AddHandler PageButton.Command, AddressOf GetPage
PageButtons.Controls.Add(PageButton)
StartIndex += PageSize
Next
'== CREATE ARRAYLIST FOR BINDING ITEM TYPES
ItemTypes = New ArrayList
DBConnection = New
SqlConnection(" server=(local);database=Northwind;integr
ated security=true;")
DBConnection.Open()
SQLString = "SELECT DISTINCT ItemType FROM products1 ORDER BY
ItemType"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
ItemTypes.Add(DBReader("ItemType"))
End While
DBReader.Close()
DBConnection.Close()
If Not Page.IsPostBack Or ViewState("Updated") = True Then
DBConnection = New
SqlConnection(" server=(local);database=Northwind;integr
ated security=true;")
DBConnection.Open()
SQLString = "SELECT TOP " & PageSize & " * FROM products1 ORDER
BY ItemNumber"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
DataGridDisplay.DataSource = DBReader
DataGridDisplay.DataBind()
DBReader.Close()
DBConnection.Close()
Dim FirstButton As Button
FirstButton = CType(PageButtons.FindControl("P1"), Button)
FirstButton.Style("background-color") = "#990000"
FirstButton.Style("color") = "#FFFFFF"
ViewState("Updated") = False
End If
End Sub
Sub GetPage(ByVal Src As Object, ByVal Args As CommandEventArgs)
Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String
Dim Keys() As String
Keys = Split(Args.CommandName, "|")
DBConnection = New
SqlConnection(" server=(local);database=Northwind;integr
ated security=true;")
DBConnection.Open()
SQLString = "SELECT * FROM products1 WHERE " & _
"ItemNumber >= '" & Keys(0) & "' AND " & _
"ItemNumber <= '" & Keys(1) & "' " & _
"ORDER BY ItemNumber"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
DataGridDisplay.DataSource = DBReader
DataGridDisplay.DataBind()
DBReader.Close()
DBConnection.Close()
'-- Highlight clicked button
Dim Item As Button
Dim ThisButton As Button
For Each Item In PageButtons.Controls
ThisButton = CType(Item, Button)
ThisButton.Style("background-color") = "#F0F0F0"
ThisButton.Style("color") = "#000000"
Next
ThisButton = CType(PageButtons.FindControl(Src.id), Button)
ThisButton.Style("background-color") = "#990000"
ThisButton.Style("color") = "#FFFFFF"
End Sub
Function SetIndex(ByVal TheItem As String)
Dim i As Integer
For i = 0 To ItemTypes.Count - 1
If TheItem = ItemTypes(i) Then
Return i
End If
Next
End Function
Sub EditRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)
Dim Command As String
Dim ItemNumber As String
Dim ItemType As String
Dim ItemSupplier As String
Dim ItemName As String
Dim ItemDescription As String
Dim ItemPrice As String
Dim ItemQuantity As String
Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String
Command = Args.CommandSource.Text
ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text
ItemType = CType(Args.Item.FindControl("ItemType"),
DropDownList).SelectedItem.Text
ItemSupplier = CType(Args.Item.FindControl("ItemSupplier"),
TextBox).Text
ItemName = CType(Args.Item.FindControl("ItemName"), TextBox).Text
ItemDescription = CType(Args.Item.FindControl("ItemDescription"),
TextBox).Text
ItemPrice = CType(Args.Item.FindControl("ItemPrice"), TextBox).Text
ItemQuantity = CType(Args.Item.FindControl("ItemQuantity"),
TextBox).Text
UpdateMessage.Text = " "
Dim ValidRecord As Boolean = True
If Command = "Add" Or Command = "Update" Then
'-- CHECK FOR VALID RECORD --
'-- Check for valid ItemNumber
If Len(ItemNumber) <> 6 Then
UpdateMessage.Text &= "- Invalid Item Number length "
ValidRecord = False
ElseIf Not IsNumeric(Right(ItemNumber, 4)) Then
UpdateMessage.Text &= "- Invalid Item Number format "
ValidRecord = False
Else
ItemNumber = UCase(ItemNumber)
End If
'-- Check for missing Item Supplier
If ItemSupplier = "" Then
UpdateMessage.Text &= "- Missing Supplier "
ValidRecord = False
End If
'-- Check for missing Item Name
If ItemName = "" Then
UpdateMessage.Text &= "- Missing Name "
ValidRecord = False
End If
'-- Check for missing Item Description
If ItemDescription = "" Then
UpdateMessage.Text &= "- Missing Description "
ValidRecord = False
End If
'-- Check for valid Item Price
If Not IsNumeric(ItemPrice) Then
UpdateMessage.Text &= "- Invalid Price format "
ValidRecord = False
End If
'-- Check for valid Item Quantity
If Not IsNumeric(ItemQuantity) Then
UpdateMessage.Text &= "- Invalid Quantity format "
ValidRecord = False
End If
If ValidRecord = True And Command = "Add" Then
'-- CHECK FOR DUPLICATE RECORD --
DBConnection = New
SqlConnection(" server=(local);database=Northwind;integr
ated security=true;")
DBConnection.Open()
SQLString = "SELECT Count(*) FROM products1 WHERE ItemNumber
= '" & ItemNumber & "'"
DBCommand = New SqlCommand(SQLString, DBConnection)
If DBCommand.ExecuteScalar() <> 0 Then
UpdateMessage.Text = "- Duplicate Item Number. Record
not added."
ValidRecord = False
End If
DBConnection.Close()
End If
End If
If ValidRecord = True Then
Select Case Command
Case "Add"
SQLString = "INSERT INTO products1 " & _
"(ItemNumber, ItemType, ItemSupplier, ItemName, " & _
"ItemDescription, ItemPrice, ItemQuantity) VALUES(" & _
"'" & ItemNumber & "', " & _
"'" & ItemType & "', " & _
"'" & Replace(ItemSupplier, "'", "''") & "', " & _
"'" & Replace(ItemName, "'", "''") & "', " & _
"'" & Replace(ItemDescription, "'", "''") & "', " & _
ItemPrice & ", " & _
ItemQuantity & ")"
UpdateMessage.Text = "- Record " & ItemNumber & " added"
Case "Update"
SQLString = "UPDATE products1 SET " & _
"ItemType = '" & ItemType & "', " & _
"ItemSupplier = '" & Replace(ItemSupplier, "'", "''")
& "', " & _
"ItemName = '" & Replace(ItemName, "'", "''") & "', "
& _
"ItemDescription = '" & Replace(ItemDescription, "'",
"''") & "', " & _
"ItemPrice = " & ItemPrice & ", " & _
"ItemQuantity = " & ItemQuantity & " " & _
"WHERE ItemNumber = '" & ItemNumber & "'"
UpdateMessage.Text = "- Record " & ItemNumber & " updated"
Case "Delete"
SQLString = "DELETE FROM products1 WHERE ItemNumber = '"
& ItemNumber & "'"
UpdateMessage.Text = "- Record " & ItemNumber & " deleted"
End Select
DBConnection = New
SqlConnection(" server=(local);database=Northwind;integr
ated security=true;")
DBConnection.Open()
DBCommand = New SqlCommand(SQLString, DBConnection)
DBCommand.ExecuteNonQuery()
DBConnection.Close()
If Command = "Add" Or Command = "Delete" Then
ViewState("Updated") = True
Page_Load(Me, EventArgs.Empty)
'Page_Load(ByRef sender As System.Object, ByRef e As
System.EventArgs)
End If
End If
End Sub
End ClassHi,
The datagrid... The datagrid isn't my thing. I used it a couple times,
got frustrated, and wrote my own. Hopefully someone in the group can point
you in the right direction. I looked through the help file that comes with
VS.Net, in VS.Net they reference .controls(0) to CType() the control:
Sub MyDataGrid_Update(sender As Object, e As DataGridCommandEventArgs)
' For bound columns the edited value is stored in a Textbox.
' The TextBox is the 0th element in the column's cell.
Dim qtyText As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)
Dim priceText As TextBox = CType(e.Item.Cells(3).Controls(0),
TextBox)
Dim item As String = e.Item.Cells(1).Text
Dim qty As String = qtyText.Text
Dim price As String = priceText.Text
Here is the link to the full source:
"ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWebUIWebControlsDataGridC
ommandEventArgsClassTopic.htm"
Open up the help and paste that in the address bar.
I would try that. I don't know why WebMatrix would work and VS.Net
wouldn't. Good luck! Ken.
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

System.NullReferenceException: Object reference not set to an inst

I'm loading an Array below but getting the error "Object reference not set t
o
an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"),
TextBox).Text' is the error line.
I DON'T KNOW WHAT I'M DOING WRONG I USED ASP.NETWebMatrix and its working
well!!
Any help!!
I have declared ItemNumber as u can see below
" :-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Load array ItemNumberList with item numbers
'Dim ItemNumberList = New ArrayList
Dim ItemNumberList = New ArrayList
DBConnection = New
SqlConnection(" server=(local);database=Northwind;integr
ated security=true;")
DBConnection.Open()
SQLString = "SELECT ItemNumber FROM products1 ORDER BY ItemNumber"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
ItemNumberList.Add(DBReader("ItemNumber"))
End While
DBReader.Close()
DBConnection.Close()
ItemNumberList.TrimToSize()
End Sub
Dim ItemNumber As String
ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).TextHi,
The code in Page_Load() has nothing to do with these two lines:
Dim ItemNumber As String
ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text
What is Args? It looks like you already know the control name. Why not?:
ItemNumber = ItemNumber.Text
That should work fine. Are the two lines of code above in another
subroutine? The code you posted doesn't seem relevant in any way to each
other. Please post a better sample of what you are trying to do. Thanks
and Good luck! Ken.
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"Patrick.O.Ige" <PatrickOIge@.discussions.microsoft.com> wrote in message
news:F81983BF-9835-4BDA-9205-18985CF18FED@.microsoft.com...
> I'm loading an Array below but getting the error "Object reference not set
to
> an instance saying 'ItemNumber =
CType(Args.Item.FindControl("ItemNumber"),
> TextBox).Text' is the error line.
> I DON'T KNOW WHAT I'M DOING WRONG I USED ASP.NETWebMatrix and its working
> well!!
> Any help!!
>
> I have declared ItemNumber as u can see below
> " :-
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> ' Load array ItemNumberList with item numbers
> 'Dim ItemNumberList = New ArrayList
> Dim ItemNumberList = New ArrayList
> DBConnection = New
> SqlConnection(" server=(local);database=Northwind;integr
ated
security=true;")
> DBConnection.Open()
> SQLString = "SELECT ItemNumber FROM products1 ORDER BY ItemNumber"
> DBCommand = New SqlCommand(SQLString, DBConnection)
> DBReader = DBCommand.ExecuteReader()
> While DBReader.Read()
> ItemNumberList.Add(DBReader("ItemNumber"))
> End While
> DBReader.Close()
> DBConnection.Close()
> ItemNumberList.TrimToSize()
> End Sub
> Dim ItemNumber As String
> ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text
>

System.NullReferenceException: Object reference not set to an inst

I'm loading an Array below but getting the error "Object reference not set to
an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"),
TextBox).Text' is the error line.
I DON'T KNOW WHAT I'M DOING WRONG I USED ASP.NETWebMatrix and its working
well!!
Any help!!

I have declared ItemNumber as u can see below
" :-

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Load array ItemNumberList with item numbers
'Dim ItemNumberList = New ArrayList
Dim ItemNumberList = New ArrayList
DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
SQLString = "SELECT ItemNumber FROM products1 ORDER BY ItemNumber"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
ItemNumberList.Add(DBReader("ItemNumber"))
End While
DBReader.Close()
DBConnection.Close()
ItemNumberList.TrimToSize()
End Sub

Dim ItemNumber As String
ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).TextHi,

The code in Page_Load() has nothing to do with these two lines:

Dim ItemNumber As String
ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text

What is Args? It looks like you already know the control name. Why not?:

ItemNumber = ItemNumber.Text

That should work fine. Are the two lines of code above in another
subroutine? The code you posted doesn't seem relevant in any way to each
other. Please post a better sample of what you are trying to do. Thanks
and Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Patrick.O.Ige" <PatrickOIge@.discussions.microsoft.com> wrote in message
news:F81983BF-9835-4BDA-9205-18985CF18FED@.microsoft.com...
> I'm loading an Array below but getting the error "Object reference not set
to
> an instance saying 'ItemNumber =
CType(Args.Item.FindControl("ItemNumber"),
> TextBox).Text' is the error line.
> I DON'T KNOW WHAT I'M DOING WRONG I USED ASP.NETWebMatrix and its working
> well!!
> Any help!!
>
> I have declared ItemNumber as u can see below
> " :-
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> ' Load array ItemNumberList with item numbers
> 'Dim ItemNumberList = New ArrayList
> Dim ItemNumberList = New ArrayList
> DBConnection = New
> SqlConnection("server=(local);database=Northwind;integrated
security=true;")
> DBConnection.Open()
> SQLString = "SELECT ItemNumber FROM products1 ORDER BY ItemNumber"
> DBCommand = New SqlCommand(SQLString, DBConnection)
> DBReader = DBCommand.ExecuteReader()
> While DBReader.Read()
> ItemNumberList.Add(DBReader("ItemNumber"))
> End While
> DBReader.Close()
> DBConnection.Close()
> ItemNumberList.TrimToSize()
> End Sub
> Dim ItemNumber As String
> ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text
Hi Ken and thanks for the reply! (My Code below!!!)
What i'm trying to do is a datagrid that has Add,Update,Delete commands.My
Add command is working but my Delete and Update command is giving error :-
System.NullReferenceException: Object reference not set to an instance of an
object.
Refering to the line code:- ItemNumber =
CType(Args.Item.FindControl("ItemNumber"), TextBox).Text
Don't know whats wrong IT WORKS WITH ASP.NETWEBMATRIX!!
But VS.Net give such errors!
Any help Thanks!!

'Option Explicit On
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls

Public Class datagrid_edit_delete
Inherits System.Web.UI.Page

'Dim ItemTypes As New ArrayList
Protected ItemTypes As New ArrayList
'Protected WithEvents ItemType As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button As System.Web.UI.WebControls.Button
Protected WithEvents PageButtons As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents UpdateMessage As System.Web.UI.WebControls.Label
Protected WithEvents DataGridDisplay As System.Web.UI.WebControls.DataGrid
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
'Dim ItemNumberList As New ArrayList

'Protected WithEvents ItemTypes As System.Web.UI.WebControls.DropDownList

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String
Dim PageSize As Integer = 6

'-- Load array ItemNumberList with item numbers
'Dim ItemNumberList = New ArrayList
Dim ItemNumberList = New ArrayList
DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
SQLString = "SELECT ItemNumber FROM products1 ORDER BY ItemNumber"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
ItemNumberList.Add(DBReader("ItemNumber"))
End While
DBReader.Close()
DBConnection.Close()
ItemNumberList.TrimToSize()

'-- Create Paging Buttons
Dim StartIndex = 0
Dim EndIndex As Integer
Dim StartKey As String
Dim EndKey As String
Dim i As Integer

PageButtons.Controls.Clear()
For i = 1 To Math.Ceiling(ItemNumberList.Count / PageSize)

EndIndex = StartIndex + PageSize - 1
If EndIndex > ItemNumberList.Count - 1 Then
EndIndex = ItemNumberList.Count - 1
End If

StartKey = ItemNumberList(StartIndex)
EndKey = ItemNumberList(EndIndex)

Dim PageButton As Button
PageButton = New Button
PageButton.Text = i
PageButton.ID = "P" & i
PageButton.CommandName = StartKey & "|" & EndKey
PageButton.Style("width") = "20px"
PageButton.Style("background-color") = "#F0F0F0"
AddHandler PageButton.Command, AddressOf GetPage
PageButtons.Controls.Add(PageButton)

StartIndex += PageSize

Next

'== CREATE ARRAYLIST FOR BINDING ITEM TYPES

ItemTypes = New ArrayList
DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
SQLString = "SELECT DISTINCT ItemType FROM products1 ORDER BY
ItemType"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
ItemTypes.Add(DBReader("ItemType"))
End While
DBReader.Close()
DBConnection.Close()

If Not Page.IsPostBack Or ViewState("Updated") = True Then

DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
SQLString = "SELECT TOP " & PageSize & " * FROM products1 ORDER
BY ItemNumber"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
DataGridDisplay.DataSource = DBReader
DataGridDisplay.DataBind()
DBReader.Close()
DBConnection.Close()

Dim FirstButton As Button
FirstButton = CType(PageButtons.FindControl("P1"), Button)
FirstButton.Style("background-color") = "#990000"
FirstButton.Style("color") = "#FFFFFF"

ViewState("Updated") = False

End If

End Sub

Sub GetPage(ByVal Src As Object, ByVal Args As CommandEventArgs)

Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String

Dim Keys() As String
Keys = Split(Args.CommandName, "|")

DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
SQLString = "SELECT * FROM products1 WHERE " & _
"ItemNumber >= '" & Keys(0) & "' AND " & _
"ItemNumber <= '" & Keys(1) & "' " & _
"ORDER BY ItemNumber"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
DataGridDisplay.DataSource = DBReader
DataGridDisplay.DataBind()
DBReader.Close()
DBConnection.Close()

'-- Highlight clicked button
Dim Item As Button
Dim ThisButton As Button
For Each Item In PageButtons.Controls
ThisButton = CType(Item, Button)
ThisButton.Style("background-color") = "#F0F0F0"
ThisButton.Style("color") = "#000000"
Next
ThisButton = CType(PageButtons.FindControl(Src.id), Button)
ThisButton.Style("background-color") = "#990000"
ThisButton.Style("color") = "#FFFFFF"

End Sub
Function SetIndex(ByVal TheItem As String)
Dim i As Integer
For i = 0 To ItemTypes.Count - 1
If TheItem = ItemTypes(i) Then
Return i
End If
Next
End Function

Sub EditRecord(ByVal Src As Object, ByVal Args As
DataGridCommandEventArgs)

Dim Command As String
Dim ItemNumber As String
Dim ItemType As String
Dim ItemSupplier As String
Dim ItemName As String
Dim ItemDescription As String
Dim ItemPrice As String
Dim ItemQuantity As String
Dim DBConnection As SqlConnection
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim SQLString As String

Command = Args.CommandSource.Text

ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text
ItemType = CType(Args.Item.FindControl("ItemType"),
DropDownList).SelectedItem.Text
ItemSupplier = CType(Args.Item.FindControl("ItemSupplier"),
TextBox).Text
ItemName = CType(Args.Item.FindControl("ItemName"), TextBox).Text
ItemDescription = CType(Args.Item.FindControl("ItemDescription"),
TextBox).Text
ItemPrice = CType(Args.Item.FindControl("ItemPrice"), TextBox).Text
ItemQuantity = CType(Args.Item.FindControl("ItemQuantity"),
TextBox).Text

UpdateMessage.Text = " "

Dim ValidRecord As Boolean = True

If Command = "Add" Or Command = "Update" Then

'-- CHECK FOR VALID RECORD --

'-- Check for valid ItemNumber
If Len(ItemNumber) <> 6 Then
UpdateMessage.Text &= "- Invalid Item Number length "
ValidRecord = False
ElseIf Not IsNumeric(Right(ItemNumber, 4)) Then
UpdateMessage.Text &= "- Invalid Item Number format "
ValidRecord = False
Else
ItemNumber = UCase(ItemNumber)
End If

'-- Check for missing Item Supplier
If ItemSupplier = "" Then
UpdateMessage.Text &= "- Missing Supplier "
ValidRecord = False
End If

'-- Check for missing Item Name
If ItemName = "" Then
UpdateMessage.Text &= "- Missing Name "
ValidRecord = False
End If

'-- Check for missing Item Description
If ItemDescription = "" Then
UpdateMessage.Text &= "- Missing Description "
ValidRecord = False
End If

'-- Check for valid Item Price
If Not IsNumeric(ItemPrice) Then
UpdateMessage.Text &= "- Invalid Price format "
ValidRecord = False
End If

'-- Check for valid Item Quantity
If Not IsNumeric(ItemQuantity) Then
UpdateMessage.Text &= "- Invalid Quantity format "
ValidRecord = False
End If

If ValidRecord = True And Command = "Add" Then

'-- CHECK FOR DUPLICATE RECORD --
DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
SQLString = "SELECT Count(*) FROM products1 WHERE ItemNumber
= '" & ItemNumber & "'"
DBCommand = New SqlCommand(SQLString, DBConnection)
If DBCommand.ExecuteScalar() <> 0 Then
UpdateMessage.Text = "- Duplicate Item Number. Record
not added."
ValidRecord = False
End If
DBConnection.Close()

End If

End If

If ValidRecord = True Then

Select Case Command

Case "Add"
SQLString = "INSERT INTO products1 " & _
"(ItemNumber, ItemType, ItemSupplier, ItemName, " & _
"ItemDescription, ItemPrice, ItemQuantity) VALUES(" & _
"'" & ItemNumber & "', " & _
"'" & ItemType & "', " & _
"'" & Replace(ItemSupplier, "'", "''") & "', " & _
"'" & Replace(ItemName, "'", "''") & "', " & _
"'" & Replace(ItemDescription, "'", "''") & "', " & _
ItemPrice & ", " & _
ItemQuantity & ")"
UpdateMessage.Text = "- Record " & ItemNumber & " added"

Case "Update"
SQLString = "UPDATE products1 SET " & _
"ItemType = '" & ItemType & "', " & _
"ItemSupplier = '" & Replace(ItemSupplier, "'", "''")
& "', " & _
"ItemName = '" & Replace(ItemName, "'", "''") & "', "
& _
"ItemDescription = '" & Replace(ItemDescription, "'",
"''") & "', " & _
"ItemPrice = " & ItemPrice & ", " & _
"ItemQuantity = " & ItemQuantity & " " & _
"WHERE ItemNumber = '" & ItemNumber & "'"
UpdateMessage.Text = "- Record " & ItemNumber & " updated"

Case "Delete"
SQLString = "DELETE FROM products1 WHERE ItemNumber = '"
& ItemNumber & "'"
UpdateMessage.Text = "- Record " & ItemNumber & " deleted"

End Select

DBConnection = New
SqlConnection("server=(local);database=Northwind;integrated security=true;")
DBConnection.Open()
DBCommand = New SqlCommand(SQLString, DBConnection)
DBCommand.ExecuteNonQuery()
DBConnection.Close()

If Command = "Add" Or Command = "Delete" Then

ViewState("Updated") = True
Page_Load(Me, EventArgs.Empty)
'Page_Load(ByRef sender As System.Object, ByRef e As
System.EventArgs)
End If

End If

End Sub

End Class
Hi,

The datagrid... The datagrid isn't my thing. I used it a couple times,
got frustrated, and wrote my own. Hopefully someone in the group can point
you in the right direction. I looked through the help file that comes with
VS.Net, in VS.Net they reference .controls(0) to CType() the control:

Sub MyDataGrid_Update(sender As Object, e As DataGridCommandEventArgs)
' For bound columns the edited value is stored in a Textbox.
' The TextBox is the 0th element in the column's cell.
Dim qtyText As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)
Dim priceText As TextBox = CType(e.Item.Cells(3).Controls(0),
TextBox)

Dim item As String = e.Item.Cells(1).Text
Dim qty As String = qtyText.Text
Dim price As String = priceText.Text

Here is the link to the full source:
"ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWebUIWebControlsDataGridC
ommandEventArgsClassTopic.htm"

Open up the help and paste that in the address bar.

I would try that. I don't know why WebMatrix would work and VS.Net
wouldn't. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

Tuesday, March 13, 2012

System.StackOverflowException

Hi All,

When I set the property of title in my class (Shown below) I get a
"Exception of type System.StackOverflowException was thrown." error message.

I'm guessing I got some sort of horrible loop going on, where did I go
wrong?

Thanks,
Simon.

Private pTitleAs String

Public Property Title() As String
Get
Return pStrTitle
End Get
Set(ByVal Value As String)
Title = pStrTitle
End Set
End PropertyHello
Change
Title = pStrTitle
to
pStrTitle = Value

Best regards,
Sherif

"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:u1VhjPBVFHA.3432@.TK2MSFTNGP10.phx.gbl...
> Hi All,
> When I set the property of title in my class (Shown below) I get a
> "Exception of type System.StackOverflowException was thrown." error
> message.
> I'm guessing I got some sort of horrible loop going on, where did I go
> wrong?
> Thanks,
> Simon.
> Private pTitleAs String
> Public Property Title() As String
> Get
> Return pStrTitle
> End Get
> Set(ByVal Value As String)
> Title = pStrTitle
> End Set
> End Property
you're setting the title of the string with pstrTitle, but the set action
itself calls the property again recursively. The solution provided by sherif
will fix the problem, i just thought you wanted to know the why.

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @. www.lulu.com/owc, Amazon.com etc
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:u1VhjPBVFHA.3432@.TK2MSFTNGP10.phx.gbl...
> Hi All,
> When I set the property of title in my class (Shown below) I get a
> "Exception of type System.StackOverflowException was thrown." error
> message.
> I'm guessing I got some sort of horrible loop going on, where did I go
> wrong?
> Thanks,
> Simon.
> Private pTitleAs String
> Public Property Title() As String
> Get
> Return pStrTitle
> End Get
> Set(ByVal Value As String)
> Title = pStrTitle
> End Set
> End Property
Never mind - Realised my properties were in a right old mess :)

"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:u1VhjPBVFHA.3432@.TK2MSFTNGP10.phx.gbl...
> Hi All,
> When I set the property of title in my class (Shown below) I get a
> "Exception of type System.StackOverflowException was thrown." error
> message.
> I'm guessing I got some sort of horrible loop going on, where did I go
> wrong?
> Thanks,
> Simon.
> Private pTitleAs String
> Public Property Title() As String
> Get
> Return pStrTitle
> End Get
> Set(ByVal Value As String)
> Title = pStrTitle
> End Set
> End Property

--
I am using the free version of SPAMfighter for private users.
It has removed 2175 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!
...but thanks for the replies (I posted my reply before yours appeared)

System.StackOverflowException

Hi All,
When I set the property of title in my class (Shown below) I get a
"Exception of type System.StackOverflowException was thrown." error message.
I'm guessing I got some sort of horrible loop going on, where did I go
wrong?
Thanks,
Simon.
Private pTitleAs String
Public Property Title() As String
Get
Return pStrTitle
End Get
Set(ByVal Value As String)
Title = pStrTitle
End Set
End PropertyHello
Change
Title = pStrTitle
to
pStrTitle = Value
Best regards,
Sherif
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:u1VhjPBVFHA.3432@.TK2MSFTNGP10.phx.gbl...
> Hi All,
> When I set the property of title in my class (Shown below) I get a
> "Exception of type System.StackOverflowException was thrown." error
> message.
> I'm guessing I got some sort of horrible loop going on, where did I go
> wrong?
> Thanks,
> Simon.
> Private pTitleAs String
> Public Property Title() As String
> Get
> Return pStrTitle
> End Get
> Set(ByVal Value As String)
> Title = pStrTitle
> End Set
> End Property
>
you're setting the title of the string with pstrTitle, but the set action
itself calls the property again recursively. The solution provided by sherif
will fix the problem, i just thought you wanted to know the why.
Regards,
Alvin Bruney - ASP.NET MVP
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @. www.lulu.com/owc, Amazon.com etc
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:u1VhjPBVFHA.3432@.TK2MSFTNGP10.phx.gbl...
> Hi All,
> When I set the property of title in my class (Shown below) I get a
> "Exception of type System.StackOverflowException was thrown." error
> message.
> I'm guessing I got some sort of horrible loop going on, where did I go
> wrong?
> Thanks,
> Simon.
> Private pTitleAs String
> Public Property Title() As String
> Get
> Return pStrTitle
> End Get
> Set(ByVal Value As String)
> Title = pStrTitle
> End Set
> End Property
>
Never mind - Realised my properties were in a right old mess :)
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:u1VhjPBVFHA.3432@.TK2MSFTNGP10.phx.gbl...
> Hi All,
> When I set the property of title in my class (Shown below) I get a
> "Exception of type System.StackOverflowException was thrown." error
> message.
> I'm guessing I got some sort of horrible loop going on, where did I go
> wrong?
> Thanks,
> Simon.
> Private pTitleAs String
> Public Property Title() As String
> Get
> Return pStrTitle
> End Get
> Set(ByVal Value As String)
> Title = pStrTitle
> End Set
> End Property
>
I am using the free version of SPAMfighter for private users.
It has removed 2175 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!
...but thanks for the replies (I posted my reply before yours appeared)