So i created a database on Microsoft SQL server 2014 called WaitListData
and created a table called Table, i added 5 columns. I want my C# program to insert data into these columns when a button is pressed.
My problem is (and i have researched this problem for hours) that no matter what i do, i always get the same error when i click my button, which is:System.Data.SqlClient.SqlException
in System.Data.dll
Obviously my application is going to be a lot more than just a button but i cannot seem to just get this basic function to work properly and its very frustrating. I can connect to database using Visual Studio's Server explorer and do whatever i want from there but that isn't what i need.
So any help on this would be very much appreciated, if anyone needs additional information then i will happily try to provide it.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("Server=PH-IT-CC1@SQLEXPRESS;Database=WaitListData;Trusted_Connection=True");
myConnection.Open();
SqlCommand myCommand = new SqlCommand("INSERT INTO Table (Firstname, Lastname, Email, Nationality, Time_Of_Play) " + "VALUES ('" + txtFirstname1.Text + "' , '" + txtLastname1.Text + "' , '" + txtEmail1.Text + "' , '" + txtNationality1.Text + "' , '" + txtTimeOfPlay1.Text + "')", myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
}