using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace studentA
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void saveButton_Click(object sender, EventArgs e)
{
string name = nameTextBox.Text;
string email = emailTextBox.Text;
string phone = phoneTextBox.Text;
string reg = regTextBox.Text;
Student student = new Student(name, email, phone, reg);
string connectionString = @"Server=.\SQLEXPRESS;Database=db;Integrated Security=true";
SqlConnection connection = new SqlConnection(connectionString);
string query = "INSERT INTO Students VALUES('" + student.Name + "','" + student.Email + "','" + student.Phone + "','" + student.Reg + "')";
SqlCommand command = new SqlCommand(query, connection);
connection.open();
int rowAffected=command.ExecuteNonQuery();
connection.close();
if (rowAffected > 0)
{
messageLabel.Text = "success";
}
else
{
messageLabel.Text = "failed";
}
Response.Write(rowAffected);
}
}
}
The error is on SqlConnection connection = new SqlConnection(connectionString); that line. I am using MSVS 2013 and microsoft sql server. I searched on google and get solution like "This can be the result of a .Net framework version incompatibility between two projects." But I don't understand about it. I also try with adding System.Data.SqlClient;