Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.odbcnet
guest book using odbc.net
simon fuller
6/16/2002 5:54:00 PM
Hi,
I have created a basic page that should write back to the
database but it doesn't. I just cant understand why! can
anyone help?
Here's the code
<%@ Page Language="C#" Debug="true" %>
<%@ Import namespace = "System.Data"%>
<%@ Import namespace = "Microsoft.Data.Odbc"%>
<%@ Assembly Name = "Microsoft.Data.Odbc" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
}
protected void Button1_Click(object sender,
System.EventArgs e)
{
string mySQLConnStr = "driver={MySQL};";
mySQLConnStr = mySQLConnStr + "server=localhost;";
mySQLConnStr = mySQLConnStr + "uid=userid;";
mySQLConnStr = mySQLConnStr + "pwd=password;";
mySQLConnStr = mySQLConnStr + "database=database;";
mySQLConnStr = mySQLConnStr + "OPTION=17923";
/* Above is option 1, 2, 512, 1024, 16384 see mySQL
manual for details. But the key is 512 Pad char
fields to full length.
*/
OdbcConnection myConnection = new OdbcConnection
(mySQLConnStr);
string SQL = "INSERT INTO Guest"+
"(Name, Email, Comments )"+
NameTextBox.Text.ToString() +"','"
+EmailTextBox.Text.ToString()
+"','"+CommentsTextBox.Text.ToString()
+"')" ;
OdbcCommand myCommand = new OdbcCommand(SQL,
myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception exp)
{
Console.WriteLine("Error: {0}", exp.Message);
Response.Redirect("error.aspx");
}
myConnection.Close();
Response.Redirect("Thanks.aspx");
}
</script>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft
Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5...
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<asp:Label id="Label1" style="Z-
INDEX: 101; LEFT: 32px; POSITION:
absolute; TOP: 73px" runat="server" Width="46px"
Height="23px">Name</asp:Label>
<asp:Label id="Label3" style="Z-
INDEX: 103; LEFT: 31px; POSITION:
absolute; TOP: 154px" runat="server">Email</asp:Label>
<asp:Label id="Label4" style="Z-
INDEX: 104; LEFT: 26px; POSITION:
absolute; TOP: 182px" runat="server">Comments</asp:Label>
<asp:TextBox id="NameTextBox"
style="Z-INDEX: 105; LEFT: 116px;
POSITION: absolute; TOP: 70px" runat="server"
Width="219px" Height="27px"></asp:TextBox>
<asp:TextBox id="EmailTextBox"
style="Z-INDEX: 107; LEFT: 114px;
POSITION: absolute; TOP: 151px" runat="server"
Width="218px" Height="28px"></asp:TextBox>
<asp:TextBox id="CommentsTextBox"
style="Z-INDEX: 108; LEFT: 13px;
POSITION: absolute; TOP: 206px" runat="server"
Width="317px" Height="145px"
TextMode="MultiLine"></asp:TextBox>
<asp:Button id="Button1" style="Z-
INDEX: 109; LEFT: 13px; POSITION:
absolute; TOP: 364px" runat="server" Width="135px"
Height="28px" Text="Sign In Guest
Book"></asp:Button>
<FONT size="5"><STRONG><U>Guest
Book:</U></STRONG></FONT>
</form>
</body>
</HTML>
3 Answers
(Douglas Laudenschlager [MS])
6/18/2002 10:52:00 PM
0
Simon,
You haven't told us what the error message is, but it looks to me like
there are lines missing from your concatenated SQL statement:
string SQL = "INSERT INTO Guest"+
"(Name, Email, Comments )"+
" VALUES ('" +
NameTextBox.Text.ToString() +"','"
+EmailTextBox.Text.ToString()
+"','"+CommentsTextBox.Text.ToString() +
"')"
It's always a good idea to Response.Write your complete statement to see
what you're really getting!
Best wishes,
-Doug
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co...
.
simon fuller
6/19/2002 10:15:00 PM
0
Hi Douglas,
The problem is, when I click the button it does nothing.
It doesnt even produce an error message! As a
complete .net novice its confusing me!!
Regards,
Simon
>-----Original Message-----
>Simon,
>
>You haven't told us what the error message is, but it
looks to me like
>there are lines missing from your concatenated SQL
statement:
>
>string SQL = "INSERT INTO Guest"+
> "(Name, Email, Comments )"+
>
> " VALUES ('" +
>
> NameTextBox.Text.ToString() +"','"
> +EmailTextBox.Text.ToString()
> +"','"+CommentsTextBox.Text.ToString() +
>
> "')"
>
>It's always a good idea to Response.Write your complete
statement to see
>what you're really getting!
>
>Best wishes,
>
>-Doug
>
>
>
>
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>
>Are you secure? For information about the Microsoft
Strategic Technology
>Protection Program and to order your FREE Security Tool
Kit, please visit
>
http://www.microsoft.co...
.
>
>.
>
(Douglas Laudenschlager [MS])
6/20/2002 10:25:00 PM
0
Simon,
You need another attribute on the Button tag to link button and event:
OnClick="Button1_Click"
Good luck,
-Doug
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
guest book using odbc.net
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password