I was following the tutorial, Intro to SQL Server with ASP.NET, and got to where I was suppose to add the highlighted code. For starters I don’t have a file called games.aspx.cs, its just games.aspx. In addition to this, the code I see on my screen doesn’t have any of the Using systems already there.
Here is what my code looks like, can someone tell me what I did wrong?
<%@ Page Language=“C#” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=“server”>
public partial class dbTest_Insert : System.Web.UI.Page
{
SqlConnection connection;
protected void Page_Load(object sender, EventArgs e)
{
connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GamesConnection"].ConnectionString);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlCommand command = new SqlCommand("INSERT INTO gameTable(gameName, gamePlatform) VALUES (@id_gameName, @id_gamePlatform)", connection);
SqlParameter nameContent = new SqlParameter("@id_gameName", SqlDbType.VarChar);
nameContent.Value = txtGameName.Text;
command.Parameters.Add(nameContent);
SqlParameter platformContent = new SqlParameter("@id_gamePlatform", SqlDbType.VarChar);
platformContent.Value = txtGamePlatform.Text;
command.Parameters.Add(platformContent);
connection.Open();
command.BeginExecuteNonQuery();
connection.Close();
Response.Redirect("Results.aspx");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
}
</script>
<html xmlns=“http://www.w3.org/1999/xhtml” >
<head runat=“server”>
<title>Untitled Page</title>
</head>
<body>
<form id=“form1” runat=“server”>
<div style=“text-align: right”>
<asp:SqlDataSource ID=“SqlDataSource1” runat=“server” ConnectionString="<%$ ConnectionStrings:GamesConnection %>"
SelectCommand=“SELECT * FROM [gameTable]”></asp:SqlDataSource>
<br />
Game Name:<asp:TextBox ID=“txtGameName” runat=“server” OnTextChanged=“txtGameName_TextChanged”></asp:TextBox><br />
<br />
Game Platform:
<asp:TextBox ID=“txtGamePlatform” runat=“server”></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID=“btnSubmit” runat=“server” Text=“Submit” OnClick=“btnSubmit_Click” /></div>
</form>
</body>
</html>