2013-12-23 37 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