使用asp.net将数据插入sql server的不同方法有哪些? [英] what are the different methods of inserting data into sql server using asp.net ?

查看:57
本文介绍了使用asp.net将数据插入sql server的不同方法有哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用asp.net?

解决方案

将数据插入sql server的不同方法是什么?我们不做你的功课:设置是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!


你可以谷歌出去不同的方式,他们会为你返回一堆结果。我不知道其中很多,但一种是默认的ASP.NET方式。否则,您可以使用.NET方法。



ASP.NET方式



以ASP.NET方式使用数据库类 [ ^ ]的WebMatrix.Data命名空间。示例代码是,



  //  打开连接 
var db = Database.Open( databaseName);
// 创建查询
var selectQuery = SELECT * FROM table_name;
// 选择结果
var result = db.Query(selectQuery);





.NET方式



在.NET中,您可以使用 System.Data.SqlClient [ ^ ]命名空间,用于处理数据库。它公开了许多类和方法来使用SQL服务器。您可以使用它们来操作SQL Server中的数据。连接字符串用于连接数据库(或服务器)。



 使用(SqlConnection conn =  new  SqlConnection(  connectionString)){
conn.Open();
// 连接已打开,
// 创建SqlCommands并工作。
}





这个.NET方法可以从我的文章中理解。请查看这篇文章 [ ^ ]。


what are the different methods of inserting data into sql server using asp.net?

解决方案

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!


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,

// 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).

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[^].


这篇关于使用asp.net将数据插入sql server的不同方法有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆