2010-08-31 148 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。

相关问题