Friday, 3 August 2012

How to bind total in footer of gridview


       For n = 0 To GridView2.Rows.Count - 1
                totalpayment += Val(GridView2.Rows(n).Cells(4).Text)
                totalred += Val(GridView2.Rows(n).Cells(9).Text)
            Next
            'Dim totalpayment As Double = Convert.ToInt64(dt.Compute("sum(PaymentAmt)", ""))
            If GridView2.Rows.Count > 0 Then
                GridView2.FooterRow.Cells(3).Text = "<b>Grand Total</b>"
                GridView2.FooterRow.Cells(4).Text = Format(totalpayment, "<b>0.00</b>")
                GridView2.FooterRow.Cells(8).Text = "<b>Grand Total</b>"
                GridView2.FooterRow.Cells(9).Text = Format(totalred, "<b>0.00</b>")
            End If
        End If
        If Request.QueryString("ete") = "1" Then
            Response.ContentType = "application/ms-excel"
            Response.AddHeader("Content-Disposition", "inline;filename=" & rptName & ".xls")
        End If

Wednesday, 18 July 2012

How to send mail in asp.Net Using c#

sing System.Net.Mail;

public partial class SendingMail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
        try
        {
            string textmag = "";
            textmag = "Sangram Singh<admin@iition.com>";
            MailMessage mgs = new MailMessage(textmag, txtEmail.Text, txtSubject.Text, txtMessage.Text);
            SmtpClient client = default(SmtpClient);
            mgs.IsBodyHtml = true;
            client = new SmtpClient();
            client.Host = "mail.gmail.com";
            client.Credentials = new System.Net.NetworkCredential("admin@gmail.com", "8717574491);
            client.Send(mgs);
            Response.Write("<script>alert('Mail send successfully...')</script>");
        }
        catch
        {
        }
        finally
        {
        }

How to convert data in binary to image format in asp.Net using c#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Diagnostics;
using System.Web;
public class HandlerStuImage : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        SqlConnection con = new SqlConnection(@"data source=.\sqlexpress; initial catalog=AdminUse; integrated security=SSPI;");
        con.Open();
        string sql = "select imagepath from binaryimg where id=@id";
        SqlCommand cmd = new SqlCommand(sql, con);
        cmd.Parameters.Add("@id", SqlDbType.Int).Value = context.Request.QueryString["Eid"];
        cmd.Prepare();
        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();
        context.Response.BinaryWrite((byte[])dr["imagepath"]);
        dr.Close();
        con.Close();
    }

    public bool IsReusable
    {
        get { return false; }
    }
 try
        {
            string Sid = "";


            cmd = new SqlCommand("InsertBinary", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@imagetype", "Student");
            cmd.Parameters.Add("@id", SqlDbType.Int);
            cmd.Parameters["@id"].Direction = ParameterDirection.Output;
            con.Open();
            if (cmd.ExecuteNonQuery() > 0)
            {
                Sid = cmd.Parameters["@id"].Value.ToString();
                if (FileUploadBinary.HasFile)
                {
                   
                    int filelength = FileUploadBinary.PostedFile.ContentLength;
                    byte[] stuImage = new byte[filelength + 1];                  
                    FileUploadBinary.PostedFile.InputStream.Read(stuImage, 0, filelength);
                    string str = "Update [binaryimg] set imagepath=@StuImage where id=" + Sid + "";
                    SqlCommand cmd1 = new SqlCommand(str, con);
                    cmd1.Parameters.AddWithValue("@StuImage", stuImage);
                    cmd1.ExecuteNonQuery();
                    //SqlCommand cmd1 = new SqlCommand(str, con);
                    //cmd1.ExecuteNonQuery();
                    Image1.ImageUrl = "~/HandlerStuImage.ashx?Eid=" + Sid;
                }
            }

Monday, 16 July 2012

Sunday, 15 July 2012

what is differences between ExecuteReader and ExecuteNonQuery and ExecuteScalar.?


Tuesday, 22 May 2012

How to find Duplicate record And delete from table .?
     Many times you can face problem of duplicate records in table.So How would you identify and delete       duplicate records in a table?
For that Firstly check if table has duplicate records or not using below query.

select [FirstName] from TableName group by  [FirstName] having COUNT(*)>1

Then Delete duplicate records.

Delete from  TableName  where [id] not in (select MAX(id) from  TableName  group by   [FirstName])

Monday, 7 May 2012

ASP.Net menu control


ASP.Net menu control not working in Google Chrome


ASP.Net menu controls breaks in Google Chrome and works fine in other browsers. Here is the hack to make it work in Google Chrome as well,
In C#
      if (Request.UserAgent.IndexOf("AppleWebKit") > 0) 
               Request.Browser.Adapters.Clear(); 
In Vb 
             if (Request.UserAgent.IndexOf("AppleWebKit") > 0) Then
                    Request.Browser.Adapters.Clear()
                    Request.Browser.Adapters.Clear()
                End If


Just add this code on your page load and the menu control will start working fine in Google Chrome as well.

Saturday, 5 May 2012

Sql Server 2008 is going to rock

Here are the top 10 reasons why.


1. In line variable assignment
     Instead of:
            DECLARE @myVar int 
            SET @myVar = 5

   you can do it in one line:
           DECLARE @myVar int = 5

2. Intellisense 
In the SQL Server Management Studio (SSMS).  This has been previously possible in SQL Server 2000 and 2005 with  use of 3rd party add-ins like SQL Prompt ($195).  But  these tools are a horrible hack at best (e.g. they hook into the editor window and try to   interpret what the application is doing). 
     
3. Math syntax like C  
      SET @i += 5.  Enough said.  They finally let a C# developer on the SQL team.