Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;

public partial class Payment : System.Web.UI.Page
{
    SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DbCafe.mdf;Integrated Security=True;User Instance=True");
    SqlCommand cmd;

    protected void Page_Load(object sender, EventArgs e)
    {
       // Response.Write("<script>alert('arr cnt= " + Session["UserId"].ToString() + " ')</script>");

     
        //To show data from billing address
        cmd = new SqlCommand("SELECT * FROM Billing_Address WHERE User_ID=" + Session["UserId"].ToString()+"", cn);
        cn.Open();
        SqlDataReader DR = cmd.ExecuteReader();

  
        if (DR.HasRows)
        {
            DR.Read();
            
            
            lblname.Text = DR["First_Name"] + DR["Last_Name"].ToString();
            Label8.Text = DR["Address"].ToString();
            Label10.Text = DR["Zip"].ToString();
            Label12.Text = DR["City"].ToString();
            Label14.Text = DR["State"].ToString();
            Label16.Text = DR["Country"].ToString();


        }
        else
        {
            Response.Write("<script>alert('!!!......Record Not Found .....!!!')</script>");
        }
        DR.Close();

        cn.Dispose();
        cn.Close();
        cmd.Dispose();


        //To show data from user table

        SqlConnection cn1 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DbCafe.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd1;

        cmd1 = new SqlCommand("SELECT * FROM User_table WHERE User_ID=" + Session["UserId"].ToString() + "", cn1);
        cn1.Open();
        SqlDataReader DR1 = cmd1.ExecuteReader();



        if (DR1.HasRows)
        {
            DR1.Read();

            lblemail.Text = DR1["Email_ID"].ToString();
            

        }
        else
        {
            Response.Write("<script>alert('!!!......Record Not Found1 .....!!!')</script>");
        }
        DR1.Close();

        cn1.Dispose();
        cn1.Close();
        cmd1.Dispose();



        //To show data from Order_master 
        //Response.Write("<script>alert('"+DateTime.Now.Date+"')</script>");


        SqlConnection cn2 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DbCafe.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd2;

        cmd2 = new SqlCommand("SELECT * FROM Order_Master WHERE User_ID=@User_Id and Order_Date=@Order_date",cn2);
        cmd2.Parameters.AddWithValue("User_Id", Session["UserId"].ToString());
        cmd2.Parameters.AddWithValue("Order_Date", DateTime.Now.Date);
        cn2.Open();

        SqlDataReader DR2 = cmd2.ExecuteReader();

        int OrN=0;

        if (DR2.HasRows)
        {
            DR2.Read();

            lblbillno.Text = DR2["Order_No"].ToString();
            txtamount.Text = DR2["GTotal_Amount"].ToString();
            OrN = Int32.Parse( DR2["Order_No"].ToString());


        }
        else
        {
            Response.Write("<script>alert('!!!......Record Not Found2 .....!!!')</script>");
        }
        DR2.Close();

        cn2.Dispose();
        cn2.Close();
        cmd2.Dispose();


        //To Show data from Order Details

       
        SqlConnection cn3 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DbCafe.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd3;

        cmd3 = new SqlCommand("SELECT * FROM My_Cart PRODUCT,FLAVOURS,SIZE,PRICE,QUANTITY,TOTAL_AMOUNT FROM PAYMENT WHERE Order_No=" + OrN + "", cn3);
        cn3.Open();


        SqlDataReader DR4 = cmd3.ExecuteReader();
        DataTable PDT = new DataTable();
        PDT.Load(DR4);
        GridView2.DataSource = PDT;
        GridView2.DataBind();
        cn3.Dispose();
        cn3.Close();
        cmd3.Dispose();



    }


    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DbCafe.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd;
        if (Page.IsValid)
        {
            if (Session["UserName"].ToString() == "")
            {
                Response.Redirect("Expire.aspx");
            }
            else
            {
                //To insert into Billing Address
                cmd = new SqlCommand("INSERT INTO CARD_DETAILS (CARD_NO,EXPIRATION,CARD_TYPE,CVV,USER_ID,ORDER_NO)values(@CARD_NO,@EXPIRATION,@CARD_TYPE,@CVV,@USER_ID,@ORDER_NO)", cn);
                cmd.Parameters.AddWithValue("@CARD_NO", TextBox10.Text);
                string exp=DropDownList4.Text+"-"+DropDownList5.Text;
                cmd.Parameters.AddWithValue("@EXPIRATION", exp);
                cmd.Parameters.AddWithValue("@CARD_TYPE", DropDownList6.Text);
                cmd.Parameters.AddWithValue("@CVV", TextBox11.Text);
                cmd.Parameters.AddWithValue("@USER_ID", Session["UserId"].ToString());
                cmd.Parameters.AddWithValue("@ORDER_NO",lblbillno.Text );
                
                cn.Open();
                int res = cmd.ExecuteNonQuery();
                //if (res == 1)
                //{
                //    Response.Write("<script>alert('!!!......Record Saved .....!!!')</script>");
                //}
                //else
                //{
                //    Response.Write("<script>alert('!!!......Record Not Saved .....!!!')</script>");
                //}
                cn.Dispose();
                cn.Close();
                cmd.Dispose();
                Response.Redirect("~/Thank_You.aspx");
            }
        }
    }
    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}


What I have tried:

Help please i tried some things but i failed to solve this problem.Give me solution
Posted
Updated 16-Mar-16 21:11pm
v2
Comments
koolprasad2003 17-Mar-16 1:45am    
which line gives you error ? Please elaborate

Few correction in below inline SQL queries:
SQL
SqlCommand cmd1;
cmd1 = new SqlCommand("SELECT * FROM User_table WHERE User_ID = '" + Session["UserId"].ToString() + "'", cn1);

SqlCommand cmd;
cmd = new SqlCommand("SELECT * FROM Billing_Address WHERE User_ID= '" + Session["UserId"].ToString()+"'", cn);

Although above one resolve your problem stills it has SQL Injection problem, so always use parameterised query like below:
SQL
SqlCommand cmd1; 
cmd1 = new SqlCommand("SELECT * FROM User_table WHERE User_ID = @UserID", cn1);
cmd1.Parameters.AddWithValue("@UserID", Session["UserId"].ToString());
 
Share this answer
 
You clearly know how to use parameterized queries, because some of your code does use them.
But half of it doesn't, and it's probably that which is giving you the problem.
You know that concatenating strings to form SQL queries risks SQL Injection, so stop doing it! Almost certainly, your other problem will go at the same time...
 
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