2010-08-31 63 views
1

這是我用來從數據庫中使用MerchantID獲取LocationID的代碼。我從Fill數據集部分獲得一個例外。請幫助我,。錯誤是將數據類型varchar轉換爲bigint。將數據類型varchar轉換爲bigint時出錯。內聯sql語句

public DataSet getLocationID(long MerchantID) 
{ 
    //long LOCID = null; 
    try 
    { 
     SqlParameter[] parameters = new SqlParameter[] 
     { 
      new SqlParameter("@merchantID",MerchantID) 
     }; 

     string strCommandText = "Select LocationID from Merchant_Location where MerchantID ='@merchantID' order by LocationID ASC"; 

     Debug.WriteLine(strCommandText); 

     DataSet pds = new DataSet(); 

     SqlHelper.FillDataset(DbConnString, System.Data.CommandType.Text, strCommandText, pds, new string[] { "LocID" }, parameters); 
     return pds; 
    } 
    catch (Exception ex) 
    { 
     //LogError("Error Occurred When Retrieving LocationID: " + MerchantID.ToString(), ex); 
     return null; 
    } 
} 
+0

是LocationID可空? – 2010-08-31 23:35:30

+0

Merchant_Location表中的MerchantID字段是varchar字段嗎? – ngroot 2010-08-31 23:35:50

回答

6

得到您的查詢文本擺脫單引號的周圍@merchantID,假設MERCHANTID是一個BIGINT。

相關問題