Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a beginer i need a coding to for inserting data in the data base, i have created table in the sql database i need to insert the data that is typed in the register form in to that sql database without using web.config
Posted
Comments
Mohd. Mukhtar 18-Jan-13 5:52am    
What have you tried? Copy your code here? And web.config file is for configuration of application we should use this file for storing / declaring application level value.

You probably do want to use web.config - in fact it is almost guaranteed you do if you are producign a web based solution, as the path to your SQL server instance is likely to be different in production and developement, so you will need two different conection strings, and web.config is where they are normally kept. Up to you though...
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
 
You have not posted any code saying, how far you have proceeded or what have you referred or tried so far.

Basically, you need the web.config file to store the connection string.

So, if you don't want to store it in web.config, then you can add one constant in the code page itself and use that. That is your preference.

But as you are a beginner, I will refer you the article Registration form example to insert user details in database using asp.net[^] to explore how to connect to database and store one registration form details.

Thanks...
 
Share this answer
 
Comments
Thanks for accepting the answer @A. Ramkumar.

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