Connection to SQL database in C #

0

Good morning, friends,

I am having a problem about database connection in particular for use in a project that captures the database information for a DataGridView, my first problem is that the table information is not coming, my doubt, I can connect the database only with the connection string, or do I need in addition to the connection string to add the database by the base date Configuration wizard of visual studio?

    
asked by anonymous 14.04.2018 / 16:06

1 answer

1

See if this example helps you:

SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = "SELECT * FROM Customers";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

reader = cmd.ExecuteReader();
// Aqui os dados são acessados através do objeto dataReader
sqlConnection1.Close();
    
14.04.2018 / 16:35