Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
create proc showdb
as
begin
  SELECT top 4 name,database_id  FROM  sys.databases     for JSON auto
end
GO


I wanted to show the result in a grid view... could you please share the code for C#?

C#
SqlCommand Objcmd = new SqlCommand();
Objcmd.Connection = ObjConn;
Objcmd.CommandType = CommandType.StoredProcedure;
Objcmd.CommandText = "showdb";
Objcmd.CommandTimeout = 0; 
SqlDataAdapter ObjAda = new SqlDataAdapter(Objcmd);

ObjAda.Fill(dset);


What I have tried:

Code I have mentioned below. I m new in C#
Posted
Updated 21-Mar-22 23:15pm
v2

1 solution

Remove the for JSON auto from your stored procedure. Your dset will then contain the source data, which you can bind directly to your datagrid.
 
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