【问题标题】:ASP.NET SqlDataSource Debug in Visual Studio 2010Visual Studio 2010 中的 ASP.NET SqlDataSource 调试
【发布时间】:2013-12-23 02:28:43
【问题描述】:

我很难使用 SqlDataSource 调试 asp.net webform 应用程序。对于插入命令 -

DataSource.ConnectionString = ConnectionManager.ConnectionString;
DataSource.ProviderName = ConnectionManager.ProviderName;
DataSource.InsertCommand = "INSERT INTO tblTest(ID, test1, test2, test3, test4, test5, test6, test7, test8) Values(@ID, @test1, @test2, @test3, @test4, @test5, @test6, @test7, @test8)"

我正在寻找带有填充参数值的完整 T-SQL 插入字符串,例如

INSERT INTO tblTest(ID, test1, test2, test3, test4, test5, test6, test7, test8) Values(a0, 1, 2, 3, 4, 5, 6, 7, 8)

目前我可以在

中设置断点
protected void DataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
}

但 SqlDataSourceStatusEventArgs 仅在单独的对象中具有 InsertCommand 和参数集合。将它们放在一起作为 T-SQL 命令非常不方便。

你们如何在 Visual Studio 中调试 SqlDataSource?

谢谢

【问题讨论】:

    标签: asp.net visual-studio-2010 tsql debugging sqldatasource


    【解决方案1】:

    以下 MSDN page 为您提供了如何在插入后获取调试信息的示例。

    Sub On_Inserted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
        Dim command As DbCommand 
        command = e.Command
    
        ' The label displays the primary key of the recently inserted row.
        Label1.Text = command.Parameters("@PK_New").Value.ToString()    
    
        ' Explicitly call DataBind to refresh the data
        ' and show the newly inserted row.
        GridView1.DataBind()
     End Sub 'On_Inserted
    

    SqlDataSource 其实还支持很多其他的事件,你也可以在 MSDN 上找到。

    最后.... 可以考虑使用 EntityFramework(不寒而栗)或其他领先的 OOR 工具之一,例如 LLBLGEN(获胜!)。他们将数据库抽象为对象模型,使开发和调试变得更加容易。

    【讨论】:

    • 感谢您的回答。在链接中获取调试信息的方式对我来说太笨拙了。我必须打印出每个参数值才能以这种方式构造一个 T-SQL 命令。有没有更好的办法?
    • 是的,看我的最后一句话:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多