I have written code to connect to insert asp.net form data into an SQL server, created in Microsoft Visual Studio 2015, using c#. The issue I am having now is that I am unable to test if form works due to a Synax error. There are spaces between the text file, I am not sure if that might be the reason why there is an error? Or misplaced connection file? I copied the pathing directly from Microsoft Access. Any advice would be greatly appreciated.
Error:
Compiler Error Message: CS1003: Syntax error, ',' expected
Source Error:
Line 11: public partial class _Default : System.Web.UI.Page
Line 12: {
Line 13: SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="C: \Users\P\Docs\Visual Studio 2015\WebSites\WebSite2\App_Data\Database.mdf";Integrated Security=True");
Line 14: protected void Page_Load(object sender, EventArgs e)
Line 15: {
Source File: C:\Users\P\Docs\Visual Studio 2015\WebSites\WebSite2\Default.aspx.cs Line: 13
This is the form code in c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="C: \Users\P\Docs\Visual Studio 2015\WebSites\WebSite2\App_Data\Database.mdf";Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Unnamed1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "insert into Table values('" + pName.Text + "','" + pEmail.Text + "')";
cmd.ExecuteNonQuery();
con.Close();
}
}