Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my store procedure.. any one can suggst me .. how to pass districtid from query string .. I use this for fatch query string value..

C#
         SqlCommand sqlCmd = new SqlCommand();
         sqlCmd.Connection = connection;
         sqlCmd.CommandType = CommandType.StoredProcedure;
         sqlCmd.CommandText = "spGetCHLDETAIL";
sqlCmd.Parameters.AddWithValue("@barcode", Request.QueryString["CHILDCODE"]);
         sqlCmd.Parameters.AddWithValue("@DistrictID", Request.QueryString["DIST_ID"]);

i want to use this DIST_ID,,CHILDCODE in my store procedure

please help

SQL
USE [SCJ]
GO
/****** Object:  StoredProcedure [dbo].[spGetCHLDETAIL]    Script Date: 03/03/2014 14:32:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- EXEC spGetFilteredChild '12','','','','','','','','','','','','','5','','','','','','','','',1,100
ALTER PROCEDURE [dbo].[spGetCHLDETAIL]
(
    @DistrictID VARCHAR(250),
    @barcode VARCHAR(50)    
)
AS
BEGIN
    SET NOCOUNT ON;
    DECLARE @FirstRow AS INT, 
    @LastRow AS INT, 
    @ChildTblName AS VARCHAR (125), 
    @FamilyTblName AS VARCHAR (125), 
    @vQuery AS NVARCHAR (MAX);
 
    SET @ChildTblName = '[' + @DistrictID + 'Child_D' + ']';
    SET @FamilyTblName = '[' +@DistrictID + 'Family_D' + ']'
    
    CREATE TABLE #tblChildFamily
    (
        scanno  NVARCHAR (255),
        distt   NVARCHAR (255),
        block   NVARCHAR (255),
        gpmctc     NVARCHAR (255),
        village     NVARCHAR (255),
        habitation   NVARCHAR (255),
        location   NVARCHAR (255),
        residing   NVARCHAR (255),
        mother_ton   NVARCHAR (255),
        pincode NVARCHAR (255),
        hhno  NVARCHAR (255),
        barcode NVARCHAR(255),
        fname  NVARCHAR (255),
        mname   NVARCHAR (255),
        gname NVARCHAR (255),
        sex     NVARCHAR (255),
        dob     NVARCHAR (255),
        social_grp   NVARCHAR (255),
        minority   NVARCHAR (255),
        total_male   NVARCHAR (255),
        total_fema   NVARCHAR (255),
        seasonal_m NVARCHAR (255),
        migration_  NVARCHAR (255),
        
        duration  NVARCHAR (255),
        lp   NVARCHAR (255),
        up NVARCHAR (255),
        sec     NVARCHAR (255),
        catch_s_lp     NVARCHAR (255),
        catch_s_up   NVARCHAR (255),
        catch_s_se   NVARCHAR (255),
        cname   NVARCHAR (255),
        class   NVARCHAR (255),
        disability NVARCHAR (255),
        sch_code  NVARCHAR (255),
         nereason NVARCHAR (255),
        droupout  NVARCHAR (255),
         
       highclass NVARCHAR (255),
        uid  NVARCHAR(255),
    );
    SET @vQuery = 'SELECT Child.scanno,Child.cname,Child.distt,Child.block,Child.gpmctc,Child.village Child.habitation, Child.barcode,Child.sex,Child.dob,Family.pincode,Family.hhno,Family.fname,Family.mname,Family.gname,Family.social_grp,Family.minority,Family.total_male,Family.total_fema,Family.seasonal_m,Family.migration_,Family.duration,Family.lp,Family.up,Family.sec,Family.catch_s_lp,Family.catch_s_up,Family.catch_s_se,Child.location,
    Child.residing,Child.mother_ton,Child.disability,Child.sch_code,Child.class,Child.nereason,Child.droupout,Child.highclass,Child.uid
    FROM ' + @ChildTblName + ' As Child WITH (NOLOCK) INNER JOIN ' + @FamilyTblName + ' AS Family WITH (NOLOCK) ON 
    Child.barcode=Family.barcode WHERE LTRIM(RTRIM(Child.cname)) <> '''' AND Child.distt = ' + @DistrictID + '';
        
  
        
    INSERT INTO #tblChildFamily (scanno, distt, block, gpmctc, village,habitation,location,residing,mother_ton,pincode,hhno,barcode,fname,mname,gname,sex,dob,social_grp,minority,total_male,total_fema,seasonal_m,migration_,duration,lp,up,sec,catch_s_lp,catch_s_up,catch_s_se,cname,class,disability,sch_code,nereason,droupout, highclass,uid)
    EXECUTE sp_executesql @vQuery;
    
    WITH     PagedGetFilteredChild
    AS       (SELECT child.scanno,Child.barcode,Child.gpmctc,Child.habitation,Child.location,Child.residing,Child.mother_ton,Child.disability,Child.sch_code,Child.class,Child.nereason,Child.droupout,Child.pincode,Child.hhno,Child.fname,Child.mname,Child.gname,Child.social_grp,Child.minority,Child.total_male,Child.total_fema,Child.seasonal_m,Child.migration_,Child.duration,Child.lp,Child.up,Child.sec,child.catch_s_lp,child.catch_s_up,Child.catch_s_se,
               Child.uid AS  [Child UID],
               
                     child.cname AS [Child Name],
                     Dist.distname AS [District Name],
                     Child.distt AS [distc ID],
                     
                     (SELECT blockname
                      FROM   dbo.BLOCK WITH (NOLOCK)
                      WHERE  distt = CHILD.distt
                             AND block = Child.block) AS [Block Name],
                     (SELECT vilname
                      FROM   dbo.VilMaster WITH (NOLOCK)
                      WHERE  vilcode = Child.Village AND VilMaster.dist = CHILD.distt AND block = Child.block
                             ) AS [Village Name],
                     '' AS [School Name],
                     Child.barcode AS [Child Code],
                     child.sex AS [Sex],
                     child.dob AS [Age],
                     Child.fname AS [Father's Name],
                     Child.mname AS [Mother's Name]
                     --Child.highclass AS [Child UID],
                     --Child.uid AS  [Child UID],
                     --Child.barcode AS [Child UID],
                     
                    
              FROM   #tblChildFamily AS Child WITH (NOLOCK)
                     INNER JOIN
                     dbo.DIST AS Dist WITH (NOLOCK)
                     ON Child.distt = Dist.distt)
        
        SELECT  scanno,barcode,gpmctc,habitation,location,residing,mother_ton,disability,sch_code,class,nereason,droupout,pincode,hhno,fname,mname,gname,social_grp,minority,total_male,total_fema,seasonal_m,migration_,duration,lp,up,sec,catch_s_lp,catch_s_up,catch_s_se,  [Child Name] AS ChildName,
                 [District Name] AS DistrictName,
                 [distc ID] as districtID,
                 [Block Name] AS BlockName,
                 [Village Name] AS VillageName,
                 [Child UID] AS [ChildUID],
                 [Sex] AS Sex,
                 [Age] AS Age,
                 [Father's Name] AS FatherName,
                 [Mother's Name] AS MotherName
                
        FROM     PagedGetFilteredChild where barcode=@barcode
       
        ORDER BY [Child Name];
    
    IF OBJECT_ID('tempdb..#tblChildFamily') IS NOT NULL
        DROP TABLE #tblChildFamily;
END
Posted
Updated 2-Mar-14 22:45pm
v2
Comments
thatraja 3-Mar-14 5:41am    
What's the problem? error message?
bindash 3-Mar-14 6:55am    
the error is:
Procedure or function 'spGetCHLDETAIL' expects parameter '@DistrictID', which was not supplied.

You already passed @districtid in your query string. Please point your problem. Thanks!
 
Share this answer
 
Comments
bindash 3-Mar-14 6:58am    
Procedure or function 'spGetCHLDETAIL' expects parameter '@DistrictID', which was not supplied.
try this
sqlCmd.Parameters.AddWithValue("@barcode", Request.QueryString["CHILDCODE"].Tostring());
sqlCmd.Parameters.AddWithValue("@DistrictID", Request.QueryString["DIST_ID"].Tostring());
 
Share this answer
 
Comments
bindash 3-Mar-14 6:58am    
the error is:
Procedure or function 'spGetCHLDETAIL' expects parameter '@DistrictID', which was not supplied.
Amalraj Ramesh 3-Mar-14 7:22am    
first you have to check the query string has value or not
if(Request.QueryString["DIST_ID"].Tostring()!=null)
bindash 4-Mar-14 5:36am    
value is passed in query string.. i check it..
sqlCmd.Parameters.AddWithValue("@barcode", Request.QueryString["CHILDCODE"].Tostring());
sqlCmd.Parameters.AddWithValue("@DistrictID", Request.QueryString["DIST_ID"].Tostring());

it is not working..
same problem is occured
Amalraj Ramesh 4-Mar-14 6:00am    
I think Request.QueryString["DIST_ID"].Tostring() is null
bindash 5-Mar-14 1:01am    
sir id is passed.. new problem is occured.

Incorrect syntax near '.'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '.'.

Source Error:


Line 51:
Line 52: SqlDataAdapter da=new SqlDataAdapter(Cmd);
Line 53: da.Fill(dt);
Line 54: if (dt.Rows.Count > 0)
Line 55: {

Source File: D:\ANIL\20012014 update-17-2\TrackSystem\TrackWebApplication\ChildInfo.aspx.cs Line: 53

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