2016-02-11 59 views
-1

我想用一個存儲過程來獲取數據到一個文本框獲得使用存儲過程中的數據爲文本框:在LINQ

var q = objcontext.sploadloandata(comboBox1.Text); 
txtcustname.Text = "what to do here"; 
txtaddress.Text = "what to do here"; 
txtmobile.Text = "what to do here"; 
txtemailid.Text = "what to do here"; 

此代碼是我的存儲過程,請給我拿出這個問題

alter proc sploadloandata 
    @customerid nvarchar(50) 
as 
begin 
    declare @today datetime 
    SET @today = dateadd(day, datediff(day, 0, current_timestamp), 0) 

    select 
     a.custid, b.name, b.mobile, b.phone, a.eligibleamt, 
     a.loanamt, a.interest, a.validity, 
     datediff(day, a.cdate, @today) as No_Of_Days, 
     round(a.loanamt * a.interest * datediff(day, a.cdate, @today)/36500, 2) as SI, 
     round(a.loanamt * a.interest * datediff(day, a.cdate, @today)/36500, 2) + a.loanamt as CHECKsi 
    from 
     tblLoanEntrydetails a, tbl_customer b 
    where 
     a.custid = b.cid 
     and b.cid = @customerid 
    order by 
     a.fororderdate desc 
end 
+1

這個問題需要更多的有點像,你想幹什麼?你是否試圖將q的屬性放入不同的文本框? –

+0

您已經成功演示瞭如何使用var來導致混淆代碼。 –

+0

@VarmaAmit除了發佈代碼之外,你在結尾做了些什麼,這些代碼實際上並不涉及任何接近你想要實現的內容?你是否執行過谷歌搜索......如果你不熟悉如何從後面的C#代碼調用存儲過程,那麼你怎麼能期望你理解比使用'Linq'更復雜的東西,在線有成千上萬的例子關於如何使用C#從數據庫返回數據,以及如何使用DataAdapter等遍歷結果集。 – MethodMan

回答

0

我找到正確的解決辦法... 請這個....

首先更換,我不得不寫

查詢
Old Query : var q = objcontext.sploadloandata(comboBox1.Text); 
New Query : var q = (from data1 in objcontext.sploadloandata(comboBox1.Text) 
       select data1).FirstOrDefault(); 

現在,我得到的所有數據到文本框中

txtcustname.Text = q.name; 
txtnetweight.Text = q.weight; 
txtmobile.Text = q.mobile; 
txtloanamt.Text = q.loanamt; 
+0

如果沒有記錄,FirstorDefault將返回null。在q上訪問name屬性會引發錯誤。您可能需要首先檢查null。 –

+0

@Andy Wiesendanger確定先生.... –