my storedprocedure is here
ALTER proc [dbo].[demo3]
@tblname varchar(max),
@clname varchar(max)
as
begin
declare @sql varchar(max)
set @sql='SELECT '+@clname+ ' from '+@tblname
exec(@sql)
print @clname
end
my .net coding is this
Dim ds As New DataSet()
cmd.Connection = con
cmd.CommandText = "demo3"
cmd.CommandType = CommandType.StoredProcedure
While (i < Session("count"))
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@tblname", Session("a"))
cmd.Parameters.AddWithValue("@clname", ListBox3.Items(i).Text)
con.Open()
Dim da = New SqlDataAdapter(cmd)
da.Fill(ds)
con.Close()
gridview1.datasource=ds
gridview1.databind
i=i+1
end while
Output:
subject mark
English
Maths
80
90