列名不明确 [英] Ambiguous column name

查看:239
本文介绍了列名不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,
我有提到3歧义的问题名称错误如下:
列名"keyID"不明确.
列名称"status"不明确.
列名称"clientid"不明确.

这是我的代码:

Dear all, 
I have the problem that mention 3 ambiguous  name error as the following:
Ambiguous column name 'keyID'.
Ambiguous column name 'status'.
Ambiguous column name 'clientid'.

And here is my code:

void bindGrid()
		{
			DataGrid1.Visible=true;

			CheckingCondition();

			MKData.DB db = new MKData.DB(connStrSel);

			try
			{
                //string strSQL1 = "SELECT recvto,recvfrom,recvtext,recvdate, price, status, keyword, seckeyword FROM "+tableName+" WITH (NOLOCK) WHERE "+ strshortcode + strkeyword + sqlDate + statusCase + strclientid + " ORDER BY recvdate DESC";
                string strSQL1 = "SELECT recvto, recvfrom, recvtext, recvdate, recvtext, K.keyword AS PrimaryKeyword, K.seckeyword AS SecondaryKeyword from "+@tableName+" R WITH (NOLOCK) INNER JOIN INAPremium..INA_Keyword K on R.recvto = K.shortcode WHERE " + strshortcode + strkeyword + sqlDate + statusCase + strclientid + " ORDER BY recvdate DESC";
                DataGrid1.DataSource = db.getDS(strSQL1).Tables [0].DefaultView;
		      DataGrid1.DataBind();
			}
			catch(Exception ex)
			{
				error.Text = System.Configuration.ConfigurationManager.AppSettings.Get("generalErr");
				Log.LogToFile(pathName + "ViewKeyword_INAReqLogBySer.log", DateTime.Now.ToString() + " " + ex.Message);
				Log.LogToFile(pathName + "ViewKeyword_INAReqLogBySer", "StackTrace: " + ex.StackTrace);
				Log.LogToFile(pathName + "ViewKeyword_INAReqLogBySer", "Source " + ex.Source);
			}

			finally
			{
				db.closeDB();
			}
		}

if(shortcode.SelectedItem.Value.Equals("0"))  //if Shortcode is not selected
			{
				strshortcode ="";

                GrabClientID(""); //02102012

                strclientid = " and clientid in (" + clientList + ") "; //02102012
                
            }
			else
			{
				strshortcode =" recvto= '"+shortcode.SelectedItem.Value.ToString()+"' and ";

                GrabClientID(shortcode.SelectedItem.Value.ToString()); //02102012

                strclientid = " and clientid in (" + clientList + ") "; //02102012
              
			}

 if (pKeyword == "All Primary Keyword")
               {
                   strkeyword = "";
               }
               else if (pKeyword != "All Primary Keyword")
               {
                   strkeyword = " keyID='" + keyID + "' AND ";
               }
               else
               {
                   strkeyword = " keyID='" + keyID + "' AND ";
               }
           }
           else
           {
               strkeyword = "";
           }

if (ddlStatus.SelectedItem.Value != "")    //if Status is selected
			{
                
				statusCase = " AND status='" + ddlStatus.SelectedItem.Value +"'" ;
			}

if(shortcode.SelectedItem.Value.Equals("0"))  //if Shortcode is not selected
			{
				strshortcode ="";

                GrabClientID(""); //02102012

                strclientid = " and clientid in (" + clientList + ") "; //02102012
               
            }
			else
			{
				strshortcode =" recvto= '"+shortcode.SelectedItem.Value.ToString()+"' and ";

                GrabClientID(shortcode.SelectedItem.Value.ToString()); //02102012

                strclientid = " and clientid in (" + clientList + ") "; //02102012
			}

并根据sql查询

and according to sql query 

SELECT recvto, recvfrom, recvtext, recvdate, recvtext, K.keyword AS PrimaryKeyword, K.seckeyword AS SecondaryKeyword 
from INA_Requestlog  R WITH (NOLOCK) INNER JOIN INAPremium..INA_Keyword K on R.recvto = K.shortcode 
WHERE  recvto= '95899' and 
 K.keyid='5624' AND 
  recvdate between ('2017-04-12') and ('2017-04-12 23:59:59.997') 
   AND status='200'
    and clientid in ('3559') 
	ORDER BY recvdate DESC

列名"keyID"不明确.
列名称"status"不明确.
列名称"clientid"不明确.

我可以解决该问题吗?

谢谢






我是开发人员中的新手.

Ambiguous column name 'keyID'.
Ambiguous column name 'status'.
Ambiguous column name 'clientid'.

May I know how to solve the problem?

Thank you.






I'm newbie in enterprise as developer.

推荐答案

尝试添加"K". keyID 状态 clientid ,例如:‘strkeyword =" K.keyID ='''"... 等.


这篇关于列名不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆