Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what are the different methods of inserting data into sql server using asp.net?
Posted
Comments
Kornfeld Eliyahu Peter 9-Nov-14 9:22am    
Please do some Google...
Maciej Los 9-Nov-14 16:31pm    
What you mean by "what are the different methods of inserting data into sql server using asp.net"?
You should be more specific and provide more details. What methods you have tried?

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
[no name] 9-Nov-14 9:39am    
+5, but most probably you don't see them in the 1.1M pool ;)
You can Google out for the "different ways" and they will return a bunch of results for you. I don't know many of them, but one is the default ASP.NET way of doing it. Otherwise you can use the .NET method.

ASP.NET way

In ASP.NET way you use the Database class[^] of the WebMatrix.Data namespace. The example code is,

C#
// open the connection
var db = Database.Open("databaseName");
// create a query
var selectQuery = "SELECT * FROM table_name";
// select the results
var result = db.Query(selectQuery);


.NET way

In .NET you can use the System.Data.SqlClient[^] namespace to work with the Databases. It exposes many classes and methods to work with the SQL server. You can use them to manipulate the data in your SQL server. Connection Strings are used to connect to the database (or the server).

C#
using (SqlConnection conn = new SqlConnection("connectionString")) {
   conn.Open();
   // connection opened, 
   // create SqlCommands and work.
}


This .NET method can be understood from my article. Please have a look at this article[^].
 
Share this answer
 
v2
Comments
[no name] 9-Nov-14 9:35am    
My 5. Bruno
Afzaal Ahmad Zeeshan 9-Nov-14 10:22am    
Thanks Bruno.
Kornfeld Eliyahu Peter 9-Nov-14 9:35am    
I can't see why ASP.NET and other .NET should be different!
(If I were you I would remove the 'ASP.NET way' part - it is just awful!!!)
[no name] 9-Nov-14 9:42am    
Why? If something has to be removed then it is the question.Insert data into SQL Server Ends anyway in "INSERT INTO...."
Kornfeld Eliyahu Peter 9-Nov-14 9:53am    
If the question is legitimate or not is irrelevant to the fact that there was an attempt to answer it.
This answer is differentiate between how ASP.NET and other .NET (WPF/WinForms?) connect database...
There are different classes (in different namespaces) to access database, but there is no difference between ASP.NET and other .NET applications...
Also the sample of such in-line select statement should be banned (and it also have nothing to do with insert...) as it is the first step to open up your application to SQL injection...

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