长时间从存储过程中获取和分配值

时间:2014-04-12 05:57:15

标签: c# sql-server stored-procedures

我有一个这样的存储过程:

ALTER PROCEDURE [dbo].[spCarCallFetch1] @Carid NVARCHAR(50)


AS

BEGIN
SET NOCOUNT ON
  SELECT

     k.HBarcode, m.make,t.Compl,
    t.plateno,t.self,t.dtime, v.vtype, l.locname,[dbo].[EDTCAL](t.TBarcode)as EDT,  t.locid,t.vtid,t.lsttic,
     c.Colname, te.UniqueName

  FROM transaction_tbl t

  left JOIN KHanger_tbl k ON t.transactID = k.transactID
  left JOIN make_tbl m ON t.mkid = m.mkid 

  left JOIN vtype_tbl v ON v.vtid = t.vtid 
  left  JOIN Location_tbl l ON t.locid = l.locid 

  left JOIN Color_tbl C ON t.colid = c.colid 
  left JOIN Terminals_tbl te ON k.tid = te.tid

 WHERE t.tbarcode = @carid 
if(select COUNT(t1.Compl) from Transaction_tbl t1 where T1.TBarcode=@Carid)=1
begin
declare @compl integer =null,
@transid integer=null,
@complid integer=null
select @transid=t.transactID from  Transaction_tbl t where t.TBarcode=@carid
Select @compl=co.Cmplid from ComplimentTransactAssign_tbl co where co.TransactID=@transid
select c.CompName,c1.Remarks from Complimentary_tbl c 
 inner join ComplimentTransactAssign_tbl c1 on c.CmplID=c1.Cmplid where c.CmplID=@compl and c1.TransactID=@transid
end
declare @locatnid integer,
@location nvarchar(100)
begin
select @locatnid= t.Locid from  Transaction_tbl t where t.TBarcode=@carid
select l1.StartTime,l1.EndTime from Location_tbl l1 where l1.Locid=@locatnid
end
END

然后我从该存储过程中获取所有值并相应地将该值分配给每个textboox ...

SqlCommand cmd23 = new SqlCommand("SpCarcallfetch1", con.connect);
cmd23.CommandType = CommandType.StoredProcedure;
cmd23.Parameters.Add("@carid", SqlDbType.VarChar, 50, ParameterDirection.Input).Value = txtTicket.Text;
dr = cmd23.ExecuteReader;

while (dr.Read) {

    if (object.ReferenceEquals(dr("vtype"), DBNull.Value)) {
        txtPtype.Text = "";
    } else {
        txtPtype.Text = dr("vtype");
    }
    if (object.ReferenceEquals(dr("locname"), DBNull.Value)) {
        txtLocation.Text = "";
    } else {
        txtLocation.Text = dr("locname");
    }
    if (object.ReferenceEquals(dr("make"), DBNull.Value)) {
        txtmake.Text = "";
    } else {
        txtmake.Text = dr("make");
    }
    if (object.ReferenceEquals(dr("plateno"), DBNull.Value)) {
        plateNo = 0;
    } else {
        plateNo = dr("plateno");
    }

    //txtmodel.Text = dr("model")
    if (object.ReferenceEquals(dr("Colname"), DBNull.Value)) {
        txtcolour.Text = "";
    } else {
        txtcolour.Text = dr("Colname");
    }
    if (object.ReferenceEquals(dr("UniqueName"), DBNull.Value)) {
        txtkeylocation.Text = "";
    } else {
        txtkeylocation.Text = dr("UniqueName");
    }
    if (object.ReferenceEquals(dr("HBarcode"), DBNull.Value)) {
        txtkeyhangerlocation.Text = "";
    } else {
        txtkeyhangerlocation.Text = dr("HBarcode");
    }
    if (object.ReferenceEquals(dr("vtid"), DBNull.Value)) {
        vtid = 0;
    } else {
        vtid = dr("vtid");
    }
    if (object.ReferenceEquals(dr("locid"), DBNull.Value)) {
        locid = 0;
    } else {
        locid = dr("locid");
    }
    if (object.ReferenceEquals(dr("EDT"), DBNull.Value)) {
        txtEdt.Text = 0;
    } else {
        txtEdt.Text = dr("EDT");
    }
    if (object.ReferenceEquals(dr("lsttic"), DBNull.Value)) {
        LstTic = 0;
    } else {
        LstTic = dr("lsttic");
    }
    if (object.ReferenceEquals(dr("dtime"), DBNull.Value)) {
        dat = DateTime.Now;
    } else {
        dat = dr("dtime");
    }

    self = dr("self");
    if (self == 0) {
        Checkselfpark.Checked = false;
    } else {
        Checkselfpark.Checked = true;
    }
}

有一段时间这需要花时间来获取每个文本框的所有细节..所以我们可以比这种方式更容易做到这一点吗?
任何帮助都非常明显..

0 个答案:

没有答案