我想获取所选langugage的数据,但此查询获取所有数据......
ALTER PROCEDURE [dbo].[sp_GetAbout]
AS
SELECT
About.[AboutID],
Languages.Name as LangCode,
[About].[AboutUs], [About].[AboutUs],
[About].[Mission], [About].[Vision], [About].[AboutPhoto],
CASE
WHEN About.IsActive = 'True'
THEN 'Active'
ELSE 'Passive'
END AS Statu
FROM
[dbo].[About]
INNER JOIN
Languages on About.LangCode = Languages.Code
WHERE
About.Statu = 'True'
ORDER BY
Statu, Languages.Name
答案 0 :(得分:0)
您应该传递语言名称的输入参数。例如
ALTER Proc [dbo].[sp_GetAbout]
@LangName nvarchar(3)
as
SELECT About.[AboutID],
Languages.Name as LangCode
,[About].[AboutUs],[About].[AboutUs],[About].[Mission],[About].[Vision],[About].[AboutPhoto],
case when About.IsActive='True' then 'Active' else 'Passive'end as Statu
FROM [dbo].[About]
INNER JOIN Languages on About.LangCode = Languages.Code
Where About.Statu='True' and LangCode = @LangName Order by Statu,Languages.Name
然后使用
进行呼叫EXEC [dbo].[sp_GetAbout] @LangName = 'ENG'
另请注意更改案例的参数类型。因为您没有提供存储语言的方式。
答案 1 :(得分:0)
您必须在过程中添加参数。
ALTER Proc [dbo].[sp_GetAbout] @Lang nvarchar(30) AS
SELECT About.[AboutID],
Languages.Name AS LangCode ,
[About].[AboutUs],
[About].[AboutUs],
[About].[Mission],
[About].[Vision],
[About].[AboutPhoto],
CASE
WHEN About.IsActive='True' THEN 'Active'
ELSE 'Passive'
END AS Statu
FROM [dbo].[About]
INNER JOIN Languages ON About.LangCode = Languages.Code
WHERE About.Statu='True'
AND LangCode = @Lang
ORDER BY Statu,
Languages.Name
然后你应该像
那样召唤它EXEC [dbo].[sp_GetAbout] @Lang = 'en-GB'
对于你的C#功能
public static DataTable GetAbout()
{
Fonksiyon f = new Fonksiyon();
SqlConnection mycon = f.Baglanti;
SqlDataAdapter da = new SqlDataAdapter("sp_GetAbout", mycon);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add("@Lang", SqlDbType.NVarChar).Value = "en-GB";
DataTable dt = new DataTable();
da.Fill(dt);
da.Dispose();
KayitSayisi = dt.Rows.Count;
return dt;
}