Thank you in advance for any help that you may have to offer. I am currently building a program with Visual Studio 2015 and am trying to write a method that will perform an INSERT INTO a table that I have already established.
When I run my code I get
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll"
exception message in my console. I am very new to SQL so any basic principles and advice would be greatly appreciated!
private void InsertIntoAccount(int number, string type, string date)
{
using (SqlConnection connection1 = new SqlConnection(connectionString))
{
//Establish a connection
connection1.Open();
string sqlstring = "INSERT INTO Account (AccountNumber, Type, DateOpened) VALUES (@number, @type, @date)";
SqlCommand cmd = new SqlCommand(sqlstring, connection1);
//Fill in parameters
cmd.Parameters.Add("@number", SqlDbType.Int).Value = number;
cmd.Parameters.Add("@type", SqlDbType.VarChar, 100).Value = type;
cmd.Parameters.Add("@date", SqlDbType.VarChar, 100).Value = date;
//Execute
//<REMOVED> cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
connection1.Close();
}
}
SQLdata types of the columnsAccountNumber, Type and DateOpenedinner exception, where most of the time the real information is provided