sun
sun

Reputation: 85

How to load data to gridview programmatically?

This is my table

A/C Type  A/c No  Mode    Amount  Balance
----------------------------------------                 C -> Credit
  A        101    C       500     1000                   D -> Debit
  B        102    D       1000    200

I want to show it in a gridview as follows....

A/C Type  A/c No  Credit   Debit     Balance
----------------------------------------
  A        101     500      -         1000
  B        102      -       1000      200

This is my code and am using C# ASP.NET and SQL SERVER...

connstr = c.Get_ConnString(StrSubbrcode[I], ConfigurationManager.ConnectionStrings["dbcon"].ToString()); //Connection string
                if (connstr != "")
                {
                    c.dr = c.ProcExeReader("SELECT....", connstr);
                    if (c.dr.Read())
                    {
                        K = K + 1;

                        c.Connect(connstr);

                        SqlDataAdapter sda = new SqlDataAdapter("SELECT..", c.con);
                        sda.Fill(ds);
                        c.con.Close();
                    }
                }

if (K > 0)
            {


                gv_deposit.DataSource = ds;
                gv_deposit.DataBind();
            }

Regards,

Upvotes: 0

Views: 1039

Answers (1)

V4Vendetta
V4Vendetta

Reputation: 38200

You should try using case in sql like

select 
case when mode ='C' then amount else '-' end as credit,
case when mode ='D' then amount else '-' end as debit
from tbl

Upvotes: 3

Related Questions