Esempio n. 1
0
        //Gets data from the database table. **Table must have a primary key to work**
        private void getData(String selectQuery)
        {
            try
            {
                SqlConnection sqlCon = new SqlConnection(conString);
                sqlCon.Open();
                SqlCommand sqlCom = new SqlCommand(selectQuery, sqlCon);
                sqlCom.CommandType = CommandType.Text;
                dataAdapter        = new SqlDataAdapter(sqlCom);
                //Creating a command builder
                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

                //Creating a new data table
                dataTable = new DataTable();
                //Filling the table from Database
                dataAdapter.Fill(dataTable);
                //Binding dataTable to bindingSource1
                bindingSource1.DataSource = dataTable;
                SQLData.DataSource        = dataTable;

                //Resizes the table.
                SQLData.AutoResizeColumns();
                SQLData.AutoResizeRows();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }