2017-10-07 61 views
1

我得到異常後的結果。爲什麼sqlcomm試圖找到doTable默認表字符串'blTableName'?我不會將此名稱發送到sqlcomm,所以我需要查看sqlcomm已執行的SQL查詢。Sqlcommand去執行

這是數據庫中添加參數「表名」表,但無論如何例外,而不是返回1

string t_table_name = "TableName"; 

try 
{ 
    BindingList<doTable> bl = new 
    daTable().getTable(CoreStatic.s_SqlServerConfigLocal, new doTable() { table_ = t_table_name, TablePK = p_doWcfTicketQueue.TablePK, TableBFK = 
    CoreStatic.s_CurrentBPK }, Enums.DynamicType.BindingList); 

    foreach (doTable item_odoTable in bl) 
    { 
     SqlConnection SqlConn = new SqlConnection(blabla); 
     SqlCommand sqlcomm = new SqlCommand("TableUpdate", SqlConn); 

     SqlConn.Open(); 

     sqlcomm.CommandType = CommandType.StoredProcedure; 

     sqlcomm.Parameters.Add(new SqlParameter() 
     { ParameterName = "@table", SqlDbType = SqlDbType.NVarChar, Direction = ParameterDirection.Input, Value = t_table_name }); 
     sqlcomm.Parameters.Add(new SqlParameter() 
     { ParameterName = "@TablePK", SqlDbType = SqlDbType.UniqueIdentifier, Direction = ParameterDirection.Input, Value = item_odoTable.TablePK }); 
     //is that possible to see sqlcomm sql query? like" insert into TableName... bla bla " 

     result = sqlcomm.ExecuteNonQuery(); 
}//try 
catch (SqlException exc) 
{ 
    //exc = invalid object name 'blTableName' 
} 
+1

,你能否告訴了'TableUpdate' SP? –

+0

exception message =「無效的對象名稱blTableName'。」 SP = @table(nvharchar(128),輸入,無默認值) @TablePK(uniqueidentifier,Input,無默認值) –

+1

使用SQL Server自帶的SQL Server Management Studio(SSMS)。該工具中有一個瀏覽器,可以查看錶和存儲過程。您需要查看數據庫中的存儲過程TableUpdate。 – jdweng

回答

0

我發現當嘗試修改存儲過程的地方我寫錯了問題。 但我還是想看到什麼是sqlcomm.ExecuteNonQuery發送一個SQL查詢語句

insert into blTableName//wrong 
insert into '[email protected]+'//right 
+1

您是否嘗試過使用https://docs.microsoft.com/zh-cn/sql/tools/sql-server-profiler/sql-server-profiler? – mjwills

相關問題