ADO.NET中的sql连接
using System.Data; // Use ADO.NET namespace
using System.Data.SqlClient;
SqlConnection thisConnection = new SqlConnection(
@"Data Source=GY; Initial Catalog=northwind;uid=sa;password=datadog"); //先建立连接
thisConnection.Open();//打开连接
SqlCommand thisCommand = thisConnection.CreateCommand();//直接指定conn的command
也可以这样 // SqlCommand cmd = new SqlCommand();
// cmd.Connection = thisConnection;
cmmand的sql命令
thisCommand.CommandText = "SELECT CustomerID, CompanyName from Customer";
SqlDataReader thisReader = thisCommand.ExecuteReader();//sqldatareader不可以用new 必须直接与command关联
//用reader读出表
while (thisReader.Read())
{
// Output ID and name columns
Console.WriteLine("\t{0}\t{1}",
thisReader["CustomerID"], thisReader["CompanyName"]);
// Close reader 用完要关闭
thisReader.Close();
相关文档:
判断连接数据库状态:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace= "System.Data.SqlClie ......
Public Function GetDataTable()
Dim myComm As New SqlClient.SqlCommand("SELECT cauth_id,cauth_name,igrade,csupauth_id,csupauth_name from MAIN_TREE01 ", sqlconnection1)
Dim sdapt As New SqlClient.SqlDataAdapter(myComm)
Dim ds As New DataSet
sdapt.Fill(ds)
R ......
第一次安装2005,花了不少精力。虽然没什么太难的,但是不知道的话会很棘手的。如果你正在安装,并且发现这篇文章,那么你很走运,你将会顺利的安装成功。
安装目录中包含Sql Server x64 和 x86, x86是32位机器的。x86中又有tools 和 Servers 。第一次安装了Servers,然 ......
★Asp.net如何连接SQL Server2000数据库★
大家好,以下是有关ASP.net连接SQL Server2000数据库的例程,
在这里和大家分享一下:
Asp.net连接SQL Server2000数据库例程详解:
<%@ Import Namespace="System.Data" %>
<%@ Import NameSp ......
SQL Server 2005 中的数据类型归纳为下列类别:
精确数字
Unicode 字符串
近似数字
二进制字符串
日期和时间
其他数据类型
字符串
在 SQL Server 2005 中,根据其存储特征,某些数据类型被指定为属于下列各组:
大值数据类型:varchar(max)、nvarchar(max) 和 varbinary(max)
大型对象数据类型:text、ntext、ima ......