Showing posts with label written. Show all posts
Showing posts with label written. Show all posts

Thursday, March 29, 2012

Please check....~~

My friend wrote me an asp mail, it's written for a flash mail, but the mail cant be deliver to mailbox...can you help me check that is there any errors in this asp form? Thxxx

<%
On Error resume Next
Dim TBdy
Dim MyCDO
CR = Chr(13)
Set MyCDO = Server.CreateObject("CDONTS.NewMail")
If IsObject (MyCDO) Then
MyCDO.From = Request("email")
MyCDO.To = "mymail@dotnet.itags.org.abc.com"
MyCDO.Subject = "Contact Form"
TBdy = "Name: " & Request("name") & CR
TBdy = TBdy & "Contact Number: " & Request("contact") & CR
TBdy = TBdy & "Company Name: " & Request("company") & CR
TBdy = TBdy & "Company Address: " & Request("address") & CR
TBdy = TBdy & "City: " & Request("city") & CR
TBdy = TBdy & "Postcode: " & Request("postcode") & CR
TBdy = TBdy & "Country: " & Request("country") & CR
TBdy = TBdy & "Enquiry About: " & Request("enquiry") & CR
TBdy = TBdy & "Contact Email: " & Request("email") & CR
TBdy = TBdy & "Enquiry/Comment: " & Request("comment")
MyCDO.Body = TBdy
MyCDO.Importance = 2 (High)
MyCDO.Send
Set MyCDO = nothing
Response.Write("&bool=success&")
Else
Response.Write("&bool=failed&")
End If
%>Welcome to the ASP.NET Forums, bunko.

However, you are in the wrong place. These forums are for developers using ASP.NET.

As you are using classic ASP, you need to direct all your questions to theASP Messageboard.
oopppssss...sorrie... wrong place.. :p

Wednesday, March 21, 2012

Please help me improve this class for accessing database data

Hi All

I've just written my first class that attempts to perform the following actions:
1. Connect to SQL Server 2000 using the connection defined in web.config
2. Execute a stored procedure (passed as a parameter) using any number of SQL parameters
3. Return the data as a dataTable back to the calling page

I need some really general advice from you experts to help improve it in the following ways if possible:
1. Reliability
2. Performance

Although it does work, it's probably quite badly written as to be honest I don't really know what I'm doing. Any help would be really appreciated! Big Smile [:D]

Namespace myNS
Public Class dataGrabber

Private Shared myConn As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnString").ConnectionString)
Private Shared mySQLCommand As New SqlCommand
Private Shared myDataReader As SqlDataReader

Public Sub New(ByVal storedProcedureToRun As String)
mySQLCommand.Connection = myConn
mySQLCommand.CommandText = storedProcedureToRun
mySQLCommand.CommandType = CommandType.StoredProcedure
End Sub

Public Sub AddParam(ByVal paramName As String, ByVal paramDataType As SqlDbType, ByVal paramValue As String)
Dim tmpParam As New SqlParameter(paramName, paramDataType)
tmpParam.Value = paramValue
mySQLCommand.Parameters.Add(tmpParam)
End Sub

Public ReadOnly Property getData() As DataTable
Get
Dim myDataTable As New DataTable
mySQLCommand.Connection.Open()
myDataReader = mySQLCommand.ExecuteReader(CommandBehavior.CloseConnection)
myDataTable.Load(myDataReader)
mySQLCommand.Parameters.Clear()
mySQLCommand.Dispose()
Return myDataTable
End Get
End Property

End Class
End Namespace

With my expereince, I always make my data layers static, there is really no need to maintain class instances in the data layer, however there are exceptions depending on the requirements of your project.

In my data layers, I execute a command like so: MyDataLayer.ExecuteDataSet(cn, "SP_NAME", object[] args);

notice the last parameter is an object array that will hold the parameters for the stored proc.

If you want some good ideas and good practices, download microsofts data access application block and look through the code. They have some good code in there that uses caching for parameters and connections, which speeds up the datalayer.

Also take a look at patterns & practices on msdn. there is alot of good info on there.


You shouldn't make your class-level variables (myConn etc) shared. And if you want to return a DataTable you could use the DataAdapter rather than getting a Reader and loading it into a DataTable.
Thanks both for your help.

>> You shouldn't make your class-level variables (myConn etc) shared
I thought Shared just meant that other subs and functions in the class could access these once they had been declared. Obviously not. What is Shared therefore?

>> if you want to return a DataTable you could use the DataAdapter rather than getting a Reader and loading it into a DataTable
Could you please provide an example of this that would fit the code above?

Thanks again guys! Big Smile [:D]
Shared means there is only one instance of the object that spans all classes. So if you create two instances of your data class they both share the same connection and command object. So if one user on your site is running SPA and at the same time another user is running SPB you will get unexpected results.

For the DataAdapter;

http://authors.aspalliance.com/aspxtreme/sys/data/Common/DataAdapterClassFill.aspx


Hi Aidy
From the examples I can see online, all use a dataAdapter to fill adataTable or dataSet. Therefore (from my basic understandingWink [;)]) I'dstill require the temporary dataTable in the class to pass back to the calling page, right?? On top of this,wouldn't the dataAdapter use more resources than the dataReader?

I'm using the class in my pages as follows;

Dim DBAccess As New myNS.dataGrabber("sp_getlogin") ' instance of class
DBAccess.AddParam("username", SqlDbType.NVarChar, loginControl.UserName) ' add param username
DBAccess.AddParam("password", SqlDbType.NVarChar, loginControl.Password) ' add param password
Dim loginTable As DataTable = DBAccess.getData() ' returns values from database to use for this user

Friday, March 16, 2012

Please help override property

Hi,
I've never developed in CSharp before and I'm trying to adapt an
existing user control written in CSharp. The user control inherits from
the DataGridColumn. I'd like for one of my controls properties to
override that of the DataGridColumn. Could somebody help with the
syntax? Currently my code for the property is as follows:
public virtual string HeaderStyle
{
get
{
object savedState = null;
savedState = this.ViewState["HeaderStyle"];
if (savedState != null)
{
return (string)savedState;
}
return "";
}
set
{
this.ViewState["HeaderStyle"] = value;
}
}
When I try to compile I get the message 'HeaderStyle hides inherited
member system.web.ui.webcontrols.datagridcolumn.headerstyle. To make
the current member override that implementation, add the override
keyword. Otherwise add the new keyword'. Please could someone confirm
that instead of
public virtual string HeaderStyle
I should have
public overrides string HeaderStyle
Thanks,
PaulI think it should be "override", without the "s".
An "override" is actually a "virtual" but it emphasize that it override
the virtual function declared in one of its base class. The thing is it
makes the purpose clearer, and avoid the case of accidental overriding
when you actually want a new virtual method, and acidentally create a
new virtual method while you actually want to overriding.