C#从SQL中选择加入但没有数据返回 [英] C# select from SQL with join but no data back

查看:71
本文介绍了C#从SQL中选择加入但没有数据返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 SqlConnection conn = new SqlConnection(Data Source = *****; Initial Catalog = ****; User ID = sa; Password = ****); 
conn.Open();

SqlCommand PaymentCommand = new SqlCommand(选择i1.job__inl为'job__inl',i1.kla__ref为'kla__ref',k1.cdeklaap为'cdeklaap',i1.bkj__ref为'bkj__ref',i1。 munt_ref为'munt_ref',v1.vdok__nr为'vdok__nr',v1.dgbk_ref为'dgbk_ref'来自hafgfk__ i1 INNER JOIN vkpdok__ v1 on i1.fak__ref = v1.fak__ref INNER JOIN klabas__ k1 on i1.kla__ref = k1.kla__ref其中i1 .fak__ref ='@ fak__ref',conn);
PaymentCommand.Parameters.AddWithValue(@ fak__ref,invid);

使用(SqlDataReader reader = PaymentCommand.ExecuteReader())
{
if(reader.Read())
{
JobInl = reader [ job__inl]的ToString();
KlaRef = reader [kla__ref]。ToString();
Cdeklaap = reader [cdeklaap]。ToString();
BkjRef = reader [bkj__ref]。ToString();
MuntRef = reader [munt_ref]。ToString();
VdokNr = reader [vdok__nr]。ToString();
DgbkRef = reader [dgbk_ref]。ToString();

}
}
conn.Close();





我尝试了什么:



你好我试图从sql服务器获取数据,但它没有得到数据回来没有错误读者是null和即时通讯100%确定有数据

解决方案

引用...这是引号。

。 .. 其中 i1.fak__ref = '  @ fak__ref' 

要求 i1.fak__ref 包含字符串 @fak__ref 而不是内容变量。

尝试删除引号:

 ... 其中 i1.fak__ref=@fak__ref 


SqlConnection conn = new SqlConnection("Data Source=*****;Initial Catalog=****;User ID=sa;Password=****");
            conn.Open();

            SqlCommand PaymentCommand = new SqlCommand("Select i1.job__inl as 'job__inl',i1.kla__ref as 'kla__ref',k1.cdeklaap as 'cdeklaap',i1.bkj__ref as 'bkj__ref',i1.munt_ref as 'munt_ref',v1.vdok__nr as 'vdok__nr',v1.dgbk_ref as 'dgbk_ref' from hafgfk__ i1 INNER JOIN vkpdok__ v1 on i1.fak__ref=v1.fak__ref INNER JOIN klabas__ k1 on i1.kla__ref=k1.kla__ref where i1.fak__ref='@fak__ref'", conn);
            PaymentCommand.Parameters.AddWithValue("@fak__ref", invid);

            using (SqlDataReader reader = PaymentCommand.ExecuteReader())
            {
                if (reader.Read())
                {
                    JobInl = reader["job__inl"].ToString();
                    KlaRef = reader["kla__ref"].ToString();
                    Cdeklaap = reader["cdeklaap"].ToString();
                    BkjRef = reader["bkj__ref"].ToString();
                    MuntRef = reader["munt_ref"].ToString();
                    VdokNr = reader["vdok__nr"].ToString();
                    DgbkRef = reader["dgbk_ref"].ToString();

                }
            }
            conn.Close();



What I have tried:

Hi pros im trying to get data from sql server but it dows not get data back wit no error reader is null and im 100% sure that there is a data

解决方案

Quotes...it's the quotes.

... where i1.fak__ref='@fak__ref'

Requires i1.fak__ref to contain the string @fak__ref not the content of the variable.
Try removing the quotes:

... where i1.fak__ref=@fak__ref


这篇关于C#从SQL中选择加入但没有数据返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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