y819508365
点红姐
2015-08-02 06:17

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

  • datagrid
  • 数据库
  • net
  • 框架

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();

    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答