Log in

View Full Version : Do you know any ASP.net? If so, i need your help!


ThomasE
November 17th, 2011, 08:38 AM
Hello VT, i'm in need of some desperate help.

I'm currently working on a website project for school. I know CSS and html fluently. But this project requires a database, so i have made a database connection using C# and a MS access database.

At the moment you can input something into the textbox and click submit, then it will added to the database. But since this is a newsletter i need something so that people can remove themselves from the database.

I was thinking i would make a textbox and if the textbox is equal to a email in the database it will be deleted. But i have no clue on how to do this.

Any help would be appreciated.
... Also, if you know how to do it with sql and Access, tell me how you would do it in sql, because i can easily translate it to the MS Access commands.

ThomasE
November 17th, 2011, 11:49 AM
This is my current .cs file. Like i have no idea what the hell i'm doing.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
using System.Configuration;


namespace WebApplication2
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string connstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(@"\App_data\users.mdb") + ";Persist Security Info=False;";
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connstring);
conn.Open();
string cmdStr = "Select count(*) from email where Email='" + TextBox1.Text + "'";
OleDbCommand userExist = new OleDbCommand(cmdStr, conn);
conn.Close();

}
}

protected void Button1_Click(object sender, EventArgs e)
{
string connstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(@"\App_data\users.mdb") + ";Persist Security Info=False;";
OleDbConnection conn = new OleDbConnection(connstring);
conn.Open();
string delCmd = "Delete from email (Email) values (@Email)";
OleDbCommand deleteUser = new OleDbCommand(delCmd, conn);
deleteUser.Parameters.AddWithValue("@Email", TextBox1.Text);

try
{
deleteUser.ExecuteNonQuery();
conn.Close();
TextBox1.Text = null;
}
finally
{
Response.Write(AlertJavascript("You have been deleted"));
}
}
private string AlertJavascript(string message)
{
return "<script type=\"text/javascript\">alert('" + message + "');</script>";
}
}
}


I basically want to delete an email from my MS access datebase.
The email which has to be deleted is an email which has been typed into Textbox1.text.

TheMatrix
November 17th, 2011, 08:44 PM
ASP.NET!?!? :eek:
Be cool and use Perl :cool:

Ummm, I'll try, but I know nothing about ASP.NET, so this may not work.
Maybe it's just my poor understanding of the language, but where do you actually use the results of the initial select query? You seem to have executed/prepared it, but I don't see where the return value gets used.

If you want me to, I can show you how to do it in Perl. But good luck :)

ThomasE
November 18th, 2011, 10:31 AM
ASP.NET!?!? :eek:
Be cool and use Perl :cool:

Ummm, I'll try, but I know nothing about ASP.NET, so this may not work.
Maybe it's just my poor understanding of the language, but where do you actually use the results of the initial select query? You seem to have executed/prepared it, but I don't see where the return value gets used.

If you want me to, I can show you how to do it in Perl. But good luck :)


Unfortunately i have to build a website using;

VB script or javascript, html and css, ASP.net OR php and then with MS Access database implemented.

But i think i solved my problem! It seems to work now.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
using System.Configuration;


namespace WebApplication2
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string connstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(@"\App_data\users.mdb") + ";Persist Security Info=False;";
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connstring);
conn.Open();
string cmdStr = "Select count(*) from email where Email='" + TextBox1.Text + "'";
OleDbCommand userExist = new OleDbCommand(cmdStr, conn);
conn.Close();

}
}

protected void Button1_Click(object sender, EventArgs e)
{
string connstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(@"\App_data\users.mdb") + ";Persist Security Info=False;";
OleDbConnection conn = new OleDbConnection(connstring);
conn.Open();
string cmd1 = "Delete from email where email='" + TextBox1.Text + "'";
OleDbCommand deleteUser = new OleDbCommand(cmd1, conn);

try
{
deleteUser.ExecuteNonQuery();
conn.Close();
TextBox1.Text = null;
Label1.Text = "Your email has been removed from the list. <br /> You will be redirected shortly.";
Label2.Text = "";
}
finally
{
Response.AddHeader("REFRESH", "3;URL=default.aspx");
}
}
private string AlertJavascript(string message)
{
return "<script type=\"text/javascript\">alert('" + message + "');</script>";
}
}
}

Hows perl, which other language does it resemble? Is it used a lot within web development? :)
I seriously have a burning passion for web development, but programming languages such as PHP, ASP.net and C# are just so overwhelming.
Javascript, xHTML/html, CSS and CSS3 are extremely simple and i love programming with them.

TheMatrix
November 18th, 2011, 07:45 PM
Hows perl, which other language does it resemble? Is it used a lot within web development? :)
I seriously have a burning passion for web development, but programming languages such as PHP, ASP.net and C# are just so overwhelming.
Javascript, xHTML/html, CSS and CSS3 are extremely simple and i love programming with them.
Perl is, I guess is sort of like PHP, but it works in a completely different way. IMHO, it's much easier to use for web development(and just general purpose scripting), because it's very expandable. We Perl programmers have this thing called CPAN, which is the official repository for Perl Modules(or plugins, if you want to call them that).

For web development, there's the Template (http://search.cpan.org/perldoc?Template) module, which seperates code logic from output(much cleaner, you know).
For a simpler solution, there's the HTML::Template (http://search.cpan.org/perldoc?HTML::Template), which is like Template, but slightly simpler(less features, though).

Here's something really simple in Perl and HTML::Template.
(Note: you may want to learn the basics of Perl and HTML::Template)

#!C:/Perl/bin/perl.exe
# ^ required

#Includes
use CGI;
use HTML::Template;

#I prefer object-oriented programming, so I'll set up some objects
my $CGI = CGI->new(); #CGI will be used for headers, parameter access, etc
my $TEMPLATE = HTML::Template->new( filename => "template.tmpl" ); #Set up the template object

#Declare some variables. Normally, you would get these from the database, enviroment, or whatever
my $foo = "bar"; #Just a string
my $int = 4; #Integer
my @array = (
[ A => "ggg",
B => "hhh",
],
[ A => "fff",
B => "sfs",
]
); #An array. Use this in a loop

#Give this data to the template
$TEMPLATE->param(
FOO => $foo,
INT => $int,
ARRAY => \@array #Passing the reference to an array (there is a backslash before the "@", but it doesn't show up for some reason)
);

#Print the template
print $CGI->header( -type => "text/html" );
print $TEMPLATE->output;

The template:

<!------------------------------------------/
File: template.tmpl
Note that the <TMPL_*> stuff gets processed and then taken out by the "compiler"
--------------------------------------------->
<html>
<head>
<title>Template test</title>
</head>
<body>
<h1>Template test</h1>
<hr noshadow>
<p>Foo is <TMPL_VAR NAME="FOO"></p>
<p>The integer is <TMPL_VAR NAME="INT"></p>
<p>Your loop is:
<ul>
<TMPL_LOOP NAME="ARRAY"> <!-- You basically call it like a variable -->
<li>A = <TMPL_VAR NAME="A"><br>B = <TMPL_VAR NAME="B"></li>
</TMPL_LOOP>
</ul>
<hr noshadow>
</body>
</html>

Although it may seem scary at first, don't worry, you'll get used to it :)

ThomasE
November 19th, 2011, 01:35 PM
Perl is, I guess is sort of like PHP, but it works in a completely different way. IMHO, it's much easier to use for web development(and just general purpose scripting), because it's very expandable. We Perl programmers have this thing called CPAN, which is the official repository for Perl Modules(or plugins, if you want to call them that).

For web development, there's the Template (http://search.cpan.org/perldoc?Template) module, which seperates code logic from output(much cleaner, you know).
For a simpler solution, there's the HTML::Template (http://search.cpan.org/perldoc?HTML::Template), which is like Template, but slightly simpler(less features, though).

Here's something really simple in Perl and HTML::Template.
(Note: you may want to learn the basics of Perl and HTML::Template)

#!C:/Perl/bin/perl.exe
# ^ required

#Includes
use CGI;
use HTML::Template;

#I prefer object-oriented programming, so I'll set up some objects
my $CGI = CGI->new(); #CGI will be used for headers, parameter access, etc
my $TEMPLATE = HTML::Template->new( filename => "template.tmpl" ); #Set up the template object

#Declare some variables. Normally, you would get these from the database, enviroment, or whatever
my $foo = "bar"; #Just a string
my $int = 4; #Integer
my @array = (
[ A => "ggg",
B => "hhh",
],
[ A => "fff",
B => "sfs",
]
); #An array. Use this in a loop

#Give this data to the template
$TEMPLATE->param(
FOO => $foo,
INT => $int,
ARRAY => \@array #Passing the reference to an array (there is a backslash before the "@", but it doesn't show up for some reason)
);

#Print the template
print $CGI->header( -type => "text/html" );
print $TEMPLATE->output;

The template:

<!------------------------------------------/
File: template.tmpl
Note that the <TMPL_*> stuff gets processed and then taken out by the "compiler"
--------------------------------------------->
<html>
<head>
<title>Template test</title>
</head>
<body>
<h1>Template test</h1>
<hr noshadow>
<p>Foo is <TMPL_VAR NAME="FOO"></p>
<p>The integer is <TMPL_VAR NAME="INT"></p>
<p>Your loop is:
<ul>
<TMPL_LOOP NAME="ARRAY"> <!-- You basically call it like a variable -->
<li>A = <TMPL_VAR NAME="A"><br>B = <TMPL_VAR NAME="B"></li>
</TMPL_LOOP>
</ul>
<hr noshadow>
</body>
</html>

Although it may seem scary at first, don't worry, you'll get used to it :)

Interesting. I will look into this. Thanks man!

ThomasE
November 20th, 2011, 02:06 PM
So now i have done a few things and attempted to publish my website.

So i publish it to http://macmiller.utommo.com
(http://macmiller.utommo.com) and everything looks and works fine. Or at least until someone tries to submit their email to the newsletter.

Then this shitstorm happens:


The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.]
System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) +1040464
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +351
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnect ion owningConnection, DbConnectionPoolGroup poolGroup) +31
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +76
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
System.Data.OleDb.OleDbConnection.Open() +43
WebApplication2.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\Tommo\Dropbox\Programming\ASP.net\Mac Miller\WebApplication2\default.aspx.cs:21
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207



The webhosting does support ASP.NET and it does support MS access databases.