Im kind of a beginner to C# and programming in genreal and in order to get better at it i created a forms application that registers customers.
At first i did this by trying to learn about OOP and now im going to the DB stuff.
I want to insert info to the database but i get the following:
The code for inserting to Db looks like this:
SqlConnection Cn = new SqlConnection(@"Data Source=ADMIN-PC\\MasterDB;Initial Catalog=Test;Integrated Security=True");
SqlCommand Command = new SqlCommand();
public void InsertInfo(string _valueOne, string _ValueTwo, string _valueThree, string _valuefour, string valueFive, string valuesix, string valueseven,
string valueeight, string valuenine, string valueten)
Command.Connection = Cn;
Command.CommandText = @"INSERT INTO CustomerInfo(Firstname,LastName,HoneNr,WorkNr,BusinessMail,PrivateMail,Street,City,Zipcode,Country)
@VALUES('" + _valueOne + "', '" + _ValueTwo + "','" + _valueThree + "','" + _valuefour + "','" + valueFive + "','" + valuesix + "', '" + valueseven + "','" + valueeight + "','" + valuenine + "','" + valueten + "')";
catch (Exception ObjException)
As soon as it comes to cn.open() it crashes and i don´t really understand what the problem is?
Also i want to get data from the Db and add this to a gridview
The code so far for this is like this:
public void GetInfo()
Command.CommandText = "SELECT * FROM CustomerInfo";
DataReader = Command.ExecuteReader();
Im kind of stuck here since i don´t know how to return the data, should i return it in a list? Also how do i add this to the gridview?
im a beginner and ive been at this for a few hours so if this is really simple for you be patient with me ill get there!