ASP.NET 在网站上显示数据的两种不同方式的优缺点

ASP.NET Pros and Cons of two different ways of displaying data on website

我知道有两种在网站上显示数据的方法。

第一种是在服务器资源管理器中添加数据库连接,然后拖动要在网页上显示的table。 Visual Studio 为您完成所有后端工作。

第二个是你只需要选择你想使用的控件,然后通过代码手动连接它,让它显示你想要的数据。您不必在服务器资源管理器中连接到数据库。后面的代码是这样的:

        SqlConnection sqlConnection = new SqlConnection(connString);
        SqlCommand command = new SqlCommand("RawToSummary", sqlConnection);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@SDate", SqlDbType.Date).Value = MySDate;
        command.Parameters.Add("@EDate", SqlDbType.Date).Value = MyEDate;
        sqlConnection.Open();
        command.ExecuteNonQuery();
        sqlConnection.Close();

private DataTable FillData(string connString, SqlCommand cmd)
{
    SqlConnection conn = new SqlConnection(connString);
    DataTable dt = null;
    try
    {
        cmd.Connection = conn;
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        SqlCommandBuilder cb = new SqlCommandBuilder(da);
        DataSet ds = new DataSet();
        da.Fill(ds, "tableName");
        dt = ds.Tables["tableName"];
    }
    catch (Exception e)
    {
        WriteLog("Error: " + e);
    }
    finally
    {
        conn.Close();
    }
    return dt;
}

我有两个问题:

1) 第二种方法叫什么?我正在尝试了解更多信息,但需要一个 Google 搜索词。

2) 每种方法的优缺点是什么?

我正在使用以下软件:Visual Studio 2010,SQL Server Management Studio 2008

Server Explorer/Database Explorer 是 Visual Studio 的服务器管理控制台。使用此 window 打开数据连接并登录到服务器并浏览其系统服务。

使用 Server Explorer/Database Explorer,我们可以查看和检索所有连接到的数据库中的信息。喜欢:

  • 列出数据库table、视图、存储过程和函数
  • 展开个人 table 以列出他们的列和触发器
  • 右键单击 table 执行操作,例如显示 table 的 数据或查看 table 的定义,从其快捷菜单。

编程方法 第二种方法是执行 DM(数据操作)和 DD(数据定义)功能的编程方法。

Server Explorer/Database Explorer 经历了相同的过程(连接数据库、查询 tables 等)但是在后台,而在编程方法中我们编写命令(queries/stored 过程) 同样。

我希望这能提供一个想法。