Groups > Asp .Net > Data Access and ObjectDataSource Control > Re: Help with database connection in C# script




Help with database connection in C# script

Help with database connection in C# script
Thu, 3 Apr 2008 23:08:44 +0000
new to asp. I need help with this code that connects to database, it is giving
me error on:

 Compiler Error Message: CS0246: The type or namespace name 'SqlConnection'
could not be found (are you missing a using directive or an assembly
reference?)

Source Error:




Line 13: {
Line 14: 
Line 15:     SqlConnection connection;
Line 16:     protected void Page_Load(object sender, EventArgs e)
Line 17:     {

 //this is the whole script without the system file paths//

public partial class dbTest_pdfForm : System.Web.UI.Page
{

    SqlConnection connection = new;
    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");

    }

}

//////please help!
Post Reply
Re: Help with database connection in C# script
Thu, 3 Apr 2008 23:35:40 +0000
At the top of your file put the directive

using System.Data.SqlClient;
Post Reply
about | contact