I am currently getting the error: System.InvalidOperationException: 'The ConnectionString property has not been initialized.' I would like some help to fix this as I am trying to input data from a c#form (multiple textboxes) to an SQL data base form my current code is
private void AcceptData()
{
using (Connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter("INPUT INTO Person", Connection))//, Connection
{
DataTable RegisterTable = new DataTable();
adapter.Fill(RegisterTable); //System.InvalidOperationException: 'The ConnectionString property has not been initialized.' TO FIX
string name = textBox1.Text;
string organisation = textBox3.Text;
DateTime Time = DateTime.Parse(textBox2.Text);
string strDateTimeIn = Time.ToString("yyyy-MM-dd HH:mm:ss.ffff");
string query = "INSERT INTO Person (Name,Organisation,TimeIn) VALUES('" + name + "','" + organisation + "','" +strDateTimeIn+ "')";
SqlCommand SignIn = new SqlCommand(query,Connection);
SignIn.ExecuteNonQuery();
}
}
Any help would be appreciated thank you
The connection string used is :string connectionString = (@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Register.mdf;Integrated Security=True");