c# - System.ArgumentException: The table type parameter must have a valid type name -
i trying pass in user defined table type query in c#.
the type defined 2 columns (org , sub org)
this code looks like:
dataset ds = new dataset(); try { datatable filteredorgsuborg = new datatable("orgsuborgvaluetype"); filteredorgsuborg.columns.add("org", typeof(string)); filteredorgsuborg.columns.add("suborg", typeof(string)); filteredorgsuborg.rows.add(org, orgsub); using (sqlconnection conn = new sqlconnection(ccon.getconn())) { using (sqlcommand cmd = conn.createcommand()) { cmd.commandtext = "select * mytable ex year = @year' , qtr = @qtr" + " , exists(select 1 @orgsuborg tt ex.org tt.org" + " , ex.orgsub = tt.suborg )"+ " order ex.org,year, qtr desc"; // 2. set command object knows // execute stored procedure // 3. add parameter command, // passed stored procedure cmd.parameters.add(new sqlparameter("@orgsuborg", filteredorgsuborg)); cmd.parameters.add(new sqlparameter("@year", year)); cmd.parameters.add(new sqlparameter("@qtr", qtr)); conn.open(); sqldataadapter sqlda = new sqldataadapter(); sqlda.selectcommand = cmd; sqlda.fill(ds); } }
am passing parameters in incorrectly?
when in sql server so:
declare @orgsuborg orgsuborgvaluetype insert @orgsuborg values ('05%','00000000') insert @orgsuborg values ('03%','00000000') ------------ complete ----------------------------------- select * mytable ex year = '2013' , qtr = '1' , exists( select 1 @orgsuborg tt ex.org tt.org , ex.orgsub = tt.suborg ) order ex.org,year, qtr desc works should.
i tried passing in so:
sqlparameter p = cmd.parameters.add(new sqlparameter("@orgsuborg", sqldbtype.structured)); p.value = filteredorgsuborg;
but getting same error
the table type parameter '@orgsuborg' must have valid type name.
could can't pass sql command, have similar code in place, works great stored procedure...?
set mapping type in sqlserver using typename property that: gets or sets type name table-valued parameter, has fix .
p.typename = "dbo.mytype";
check table-valued parameters post
Comments
Post a Comment