sql server - SQL Create View query Executes successfully in Management studio but fails in C# code -


this question has answer here:

here code

                   cmd.connection = con;                    if (con.state == connectionstate.closed)                    {                        con.open();                    }                    cmd.commandtext = "drop view [picklist]";                    cmd.executenonquery();                     cmd.commandtext = "create view [picklist] select a.desp_no,a.desp_date,a.custid,a.comp_name,a.ref_no,b.item_code itemid,b.pqty,c.serial_no,c.batchno,c.expiry,d.item_name,d.item_code,d.mrp,e.cust_name,e.address1,e.address2,e.address3,e.phone,e.email dbo.tbl_despdet inner join dbo.tbl_desp_sub b on a.desp_no=b.desp_no inner join dbo.tbl_desp_barcode c on c.desp_no=a.desp_no inner join tbl_itemmast d on d.item_id=b.item_code inner join dbo.tbl_custmast e on a.custid=e.cust_id  a.desp_no=@despno";                    cmd.parameters.addwithvalue("@despno", beobj._desno);                    try                     {                        cmd.executenonquery();                        return true;                    }                    catch(exception ex)                    {                        return false;                    } 

the same create view statement(with copy paste) works in sql server management studio.some 1 me stuck in fix.

update:

the name of view given [picklist] testing only.even have tried removind square brackets , found no difference.

views cannot contain @parameters. create stored procedure (create procedure ...) first, , in c# code, set name of stored procedure cmd.commandtext. or alternatively, remove create view part altogether, , keep query content of cmd.commandtext.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -