C#,wpf框架,点击之后数据库的值返回到窗口中的datagrid上显示,不能返回结果

private void button5_Click(object sender, RoutedEventArgs e)
{
//this.Hide();
// MessageBox.Show("登陆成功!!!");
string constr = "server=PC-20150723QMEF;database=dhj;integrated security=SSPI";
SqlConnection con = new SqlConnection(constr);
DataTable dt = new DataTable();
try
{

            con.Open();
            string sql = "select * from test ";
            //SqlCommand cmd = new SqlCommand(sql, con);

            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(sql, con);
            sda.Fill(ds, "test");
            dt = ds.Tables["test"];

        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        MessageBox.Show("已读取数据");
        ****return dt;****
        con.Close();

        Window2 girl = new Window2();
        girl.Show();

    }

如果你要 return dt,你需要定义一个包含返回值类型为 datatable 的方法, 不能直接写在事件处理中。