Populate a datagridview with sql query results

前端 未结 9 1113
旧巷少年郎
旧巷少年郎 2020-12-02 23:02

I\'m trying to present query results, but I keep getting a blank data grid. It\'s like the data itself is not visible

Here is my code:

 private void         


        
9条回答
  •  甜味超标
    2020-12-02 23:32

    String strConnection = Properties.Settings.Default.BooksConnectionString;
    SqlConnection con = new SqlConnection(strConnection);
    
    SqlCommand sqlCmd = new SqlCommand();
    sqlCmd.Connection = con;
    sqlCmd.CommandType = CommandType.Text;
    sqlCmd.CommandText = "Select * from titles";
    SqlDataAdapter sqlDataAdap = new SqlDataAdapter(sqlCmd);
    
    DataTable dtRecord = new DataTable();
    sqlDataAdap.Fill(dtRecord);
    dataGridView1.DataSource = dtRecord;
    

提交回复
热议问题