C# 使用sqlserver2000
来源:互联网 发布:奥运会排球编程表 编辑:程序博客网 时间:2024/05/21 15:48
using System.Data.SqlClient;
建立连接
SqlConnection myConnection = new SqlConnection("数据库连接字符串");
数据库连接字符串通常是:Data Source=localhost;Initial Catalog=数据库名;User ID=用户名;Password=密码
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = "select count(*) from 要查询的表名 where 查询的字段名= '"+保存查询值的变量名+"'";
myCommand.Connection = myConnection;
try
{
myCommand.Connection.Open();
int count = (int)myCommand.ExecuteScalar();
if (count > 0)
{
count大于0表示有,调用自己写的一个方法来更新
UpdateData();
}
else
{
小于0表示没有,调用这个方法来插入
InsertData();
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
UpdateData方法
public void UpdateData()
{
SqlConnection myConnection = new SqlConnection("数据库连接字符串");
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = "用来更新的SQL语句";
myCommand.Connection = myConnection;
try
{
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
InsertData方法
public void InsertData()
{
SqlConnection myConnection = new SqlConnection("数据库连接字符串");
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = "用来插入的SQL语句";
myCommand.Connection = myConnection;
try
{
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
- C# 使用sqlserver2000
- C# sqlserver2000
- C# sqlserver2000
- c# 连接sqlServer2000
- SQLServer2000中的触发器使用
- robot连接,使用SQLSERVER2000数据库
- SQLServer2000索引结构及其使用
- 使用jtds连接sqlserver2000数据库
- SQLServer2000索引结构及其使用
- SqlServer2000
- SqlServer2000
- SQLServer2000
- sqlserver2000數據類型同c#中的數據對應關系表
- C# 连接sqlserver2000的有效连接串~~
- SqlServer2000与C#中类型对应表
- C#怎样远程连接SQLServer2000数据库?
- SqlServer2000中用户自定义数据类型的使用
- 使用SQLServer2000 发送邮件详细配置过程
- c# md5 加密函数
- 让c#多点代码段
- 用C# 屏蔽系统热键(包括禁止使用任务管理器)
- 第一次上传到虚拟主机经历
- 阿里巴巴的一个笔试题
- C# 使用sqlserver2000
- 外语学习的真实方法与误区7
- VC++程序调试入门
- Visual Studio 快捷键
- 把一个文件拆成两个文件
- HttpHandler解析并展示PDF文档内容
- 用户登陆和注销方式
- 计算进程(经典面试题) fork() 用法(转)
- SQL Server 数据库管理常用的SQL和T-SQL语句