Click here to Skip to main content
15,887,312 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have aspx page ,I need to write the sql commands in aspx page can any one reply me how can I write sql commands in aspx page
Posted
Comments
Uday P.Singh 16-Feb-12 3:18am    
not clear why would you do that?
SAM_India 16-Feb-12 3:21am    
Hi ,
Uday thanks for blaze response.I am working for payment gateway.So I have page i.e gets values after paying amount and it is aspx page.After getting values I need to save truncations Id's and another information into database

1 solution

Put them in the code behind:
Try:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT iD, description FROM myTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            while (reader.Read())
                {
                int id = (int) reader["iD"];
                string desc = (string) reader["description"];
                ...
                }
            }
        }
    }


C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 
Comments
SAM_India 16-Feb-12 4:10am    
Hi Griff,
Thank you so much for providing me good information.But I need to write the code only in aspx page instead of aspx.cs page.I am working on Payment gateway,So I am receiving values after paying them amount ,These values need to save in database.The aspx page is provided by bank,In this page I need to store values.Hope you reply me

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