How to call the values ​of all the selections on the web page in C # asp.net

41 Views Asked by At
create procedure [dbo].[CountPermits]
(
   @CodeMelli nvarchar(50)    
)

AS
BEGIN
select count(PermitType) as AllPermit from dbo.Permit where CodeMelli=@CodeMelli
select count(PermitType) as ColdPermit from dbo.Permit where CodeMelli=@CodeMelli and PermitType='01'
select count(PermitType) as HotPermit from dbo.Permit where CodeMelli=@CodeMelli and PermitType='10'
select count(ENDTik) as FinishPermit from dbo.Permit where CodeMelli=@CodeMelli and ENDTik like '%[1]%'
select count(ENDTik) as  UnFinishPermit from dbo.Permit where CodeMelli=@CodeMelli and ENDTik='0000'

end
GO
2

There are 2 best solutions below

1
Kovid Purohit On

Yes, You can fetch multiple tables using a dataset where it will return an array of DataTables object.

The Same question has been answered over here

2
Manoj On
 public IActionResult Index()
        {
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("Connection"))
    {
        using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
        {
            cmd.CommandText = "dbo.CountPermits";
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@CodeMelli", codeMelli);
            conn.Open();
    
            System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(cmd);
    
            DataSet ds = new DataSet();
            adapter.Fill(ds);
    
            conn.Close();
        }
    }
    return View(ds);
    
    in cs.html you can use
    
    @using System.Data
    @model DataSet
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <table cellpadding="0" cellspacing="0">
            <tr>
                <th>AllPermit</th>
            </tr>
            @foreach (DataRow row in Model.Tables[0].Rows)
            {
                <tr>
                    <td>@row["AllPermit"]</td>
                </tr>
            }
        </table>
    <table cellpadding="0" cellspacing="0">
            <tr>
                <th>ColdPermit</th>
            </tr>
            @foreach (DataRow row in Model.Tables[1].Rows)
            {
                <tr>`enter code here`
                    <td>@row["ColdPermit"]</td>
                </tr>
            }
        </table>
    </body>
    </html>