Click here to Skip to main content
15,868,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii all.. this is error in my page when i try to fatch data in labels from sql server using store procedure..
PLEASE HELP thanks in advance.

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
Posted
Comments
Krunal Rohit 5-Mar-14 1:00am    
Paste your entire code.

-KR
thatraja 5-Mar-14 1:57am    
Put these details in your question with proper formatting
bindash 5-Mar-14 2:38am    
tis is my childinfo.aspx.cs code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace TrackWebApplication
{
public partial class ChildInfo : System.Web.UI.Page
{

private string barcode = "";
private string dstid = "";
protected void Page_Load(object sender, EventArgs e)
{

GetData();

}

private void GetData()
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection("Data Source=SCJ-454B2938AB1\\SCJ;Integrated Security=true;Initial Catalog=SCJ");
connection.Open();
SqlCommand Cmd = new SqlCommand();

Cmd.Connection = connection;
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.CommandText = "spGetCHLDETAIL";


Cmd.Parameters.AddWithValue("@barcode", Request.QueryString["CHILDCODE"]);
Cmd.Parameters.AddWithValue("@DistrictID", Request.QueryString["DIST_ID"]);


SqlDataAdapter da=new SqlDataAdapter(Cmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{

lbdscde.Text = dt.Rows[0]["distt"].ToString();
lbblcde.Text = dt.Rows[0]["block"].ToString();
lbgpcde.Text = dt.Rows[0]["gpmctc"].ToString();
lbvlcde.Text = dt.Rows[0]["village"].ToString();
lbhbcde.Text = dt.Rows[0]["habitation"].ToString();
lblocde.Text = dt.Rows[0]["location"].ToString();
lbchrcde.Text = dt.Rows[0]["residing"].ToString();
lbmtcde.Text = dt.Rows[0]["mother_ton"].ToString();

lbpncde.Text = dt.Rows[0]["pincode"].ToString();

lbhsno.Text = dt.Rows[0]["hhno"].ToString();

lbfthr.Text = dt.Rows[0]["fname"].ToString();

lbmthr.Text = dt.Rows[0]["mname"].ToString();

lbgrdn.Text = dt.Rows[0]["gname"].ToString();

lbscgp.Text = dt.Rows[0]["social_grp"].ToString();
lbmtcde.Text = dt.Rows[0]["minority"].ToString();
lbmle.Text = dt.Rows[0]["total_male"].ToString();
lbfmle.Text = dt.Rows[0]["total_fema"].ToString();

lbscmg.Text = dt.Rows[0]["seasonal_m"].ToString();
lbmgtyp.Text = dt.Rows[0]["migration_"].ToString();
lbdrmg.Text = dt.Rows[0]["duration"].ToString();

lbnhscll.Text = dt.Rows[0]["lp"].ToString();
lbnhsclu.Text = dt.Rows[0]["up"].ToString();
lbnhsclsc.Text = dt.Rows[0]["sec"].ToString();

lbctscll.Text = dt.Rows[0]["catch_s_lp"].ToString();
lbctsclU.Text = dt.Rows[0]["catch_s_up"].ToString();
lbctsclsc.Text = dt.Rows[0]["catch_s_se"].ToString();

lbchldnme.Text = dt.Rows[0]["cname"].ToString();

lbsex.Text = dt.Rows[0]["sex"].ToString();
lbdob.Text = dt.Rows[0]["dob"].ToString();
lbdsabty.Text = dt.Rows[0]["disability"].ToString();

lbschcde.Text = dt.Rows[0]["sch_code"].ToString();
lbclass.Text = dt.Rows[0]["class"].ToString();

lbNErsn.Text = dt.Rows[0]["nereason"].ToString();
lbDRPrsn.Text = dt.Rows[0]["droupout"].ToString();
lbhgcls.Text = dt.Rows[0]["highclass"].ToString();

}
connection.Close();
}


}
}












bindash 5-Mar-14 2:40am    
this is my store procedue spGetCHLDETAIL

USE [SCJ]
GO
/****** Object: StoredProcedure [dbo].[spGetCHLDETAIL] Script Date: 03/05/2014 10:48:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

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 INNER JOIN ' + @FamilyTblName + ' AS Family ON
Child.barcode=Family.barcode WHERE LTRIM(RTRIM(Child.cname)) <> '''' AND Child.distt = ' + @DistrictID + '';



INSERT INTO #tblChildFamily (scanno,cname,distt,block,gpmctc,village,habitation,barcode,sex,dob,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,location,
residing,mother_ton,disability,sch_code,class,nereason,droupout,highclass,uid)
EXECUTE sp_executesql @vQuery;


select scanno,cname,distt,block,gpmctc,village,habitation,sex,dob,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,location,
residing,mother_ton,disability,sch_code,class,nereason,droupout,highclass

FROM #tblChildFamily where barcode=@barcode

DROP TABLE #tblChildFamily;
END
Ramug10 5-Mar-14 1:04am    
show me your whole code..

1 solution

Your query seems to be not formed properly write print @vQuery before EXECUTE sp_executesql @vQuery; and run the printed statement in new window and you will find issue easily.
 
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