C#连接sqlserver数据库
当在C#语言中,连接sql数据库的时候,常用到sqlconnection建立与数据库的连接。 语法如下:
String sqlcon = "***";//这里是一个字符串,具体跟数据库的验证方式有关。
//sql server 身份验证 连接字符串
private string ConnstrSqlServer = "server=服务器名称;uid=登录名称;pwd=登录密码;database=数据库名称";
//windows 身份验证连接字符串
private string ConnstrWindows = "server=服务器名称;database=数据库名称;Trusted_Connection=SSPI";
SqlConnection connection = new SqlConnection(sqlcon);
例如:
SqlConnection connection = new SqlConnection("server=(local);database=dotNET_lab;Trusted_Connection=SSPI");
//windows验证方式 。
SqlConnection connection = new SqlConnection("server=(local);uid=sa;password=sa;database=dotNET_lab");
//混合验证方式 。
然后,
try {
connection.Open();
SqlCommand command = new SqlCommand("select count(*) from admin where username='"+username+"' and password='"+password+"'",connection);
SqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
n = reader.GetInt32(0);//n是在之前定义的,如果n>0,显然就存在这样一个用户。
}
//Console.WriteLine(reader.GetString(1));
}
catch(SqlException ex) {
&n
相关文档:
sqlserver数据库:java连接sqlserver2005数据库心得体会
首先得下载驱动程序到微软网站下载Microsoft SQL Server 2005 JDBC Driver 1.2 解压Microsoft SQL Server 2005 jdbc driver1.2.exe
得到sqljdbc.jar,用得时候直接加到classpath中去.
设置SQL Server服务器
防止出现
com.mi ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Timers;
using System.Data;
using System.Data.SqlClient;
namespace SMS_joke
{
/// <summary>
/// Global 的摘要说明。
/// </summary>
public class ......
在写sql语句时,一般都是一句解决,从来没想过说,把sql语句拆开来写。
例如下面这句: string readstring = "select * from 实例 where 实例ID='"+eid+"'";
然后执行 Myconnection();
DataSet ds = new DataSet();
OleD ......
记录一下以备下次快速找到。。。
往tb_wf_privgrant表中插入一条记录,workflow_id字段值从tb_wf_workflow 表中获取workflow_name='知识审核'的所有记录中workflow_id最大值。
--oracle
declare a NUMBER(10);
begin
select max(wo ......