how to do dynamic sql query in vb.net? -
i'm trying dynamic sql query in vb.net declare 2 variable , pass select on each variable
dim cmd new sqlcommand("declare @val1 int " & _ "declare @val2 int " & _ "set @val1 = 'select count(*) table1tbl'" & _ "set @val2 = 'select count(*) table2tbl'", conn) dim rdr sqldatareader = cmd.executereader rdr.read() dim str1 = rdr("@val1") dim str2 = rdr("@val2") rdr.close()
i know code not right..so how makes right ? tnx in advance
you can't sqlcommand, execute code you'd have create stored procedure , add end:
select @val1, @val2
to return values table creating.
i assume doing more creative actual example, there anyway of including in select statement? correct version should go this:
select (select count(*) table1tbl), (select count(*) table2tbl)
that return data in format want can read code have posted.
Comments
Post a Comment