2013-12-23 123 views
0

我很难用SqlDataSource调试asp.net webform应用程序。 INSERT命令 -在Visual Studio 2010中调试ASP.NET SqlDataSource

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?

感谢

回答

0

以下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(win!)。他们把数据库抽象成一个开发和调试的对象模型,要容易得多。

+0

感谢您的回答。在链接中获取调试信息的方式对我来说太笨拙。我必须打印出每个参数值才能以这种方式构建T-SQL命令。有没有更好的方法? – Don

+0

是的,看我最后一句话:) – robnick