Click here to Skip to main content
15,913,836 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 21-Oct-18 4:57am

1 solution

Quotes...it's the quotes.
SQL
... 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:
SQL
... where i1.fak__ref=@fak__ref
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900