C#查询和插入数据到sql数据库

本文介绍了使用C#连接和操作SQL Server数据库的方法,包括建立连接、查询用户ID以及插入日志数据的详细步骤。通过配置连接字符串、执行SQL命令实现数据交互。
摘要由CSDN通过智能技术生成
连接sql数据库步骤:
1. vs10 -> Tools -> Connect to Database ->Microsoft SQL Server -> 填写Server name : Use SQL Server Authentication (常用方式):Select or enter a database name -> OK
2. 在Server Explorer 中选择连到的数据库右键选属性获取连接字符串。
3. 在webconfig中创建AppSetting节点key为connectionAWGDB值为连接字符串
private SqlConnection _getConnection()   //得到连接对象
{
try  {
    string connectionString = ConfigurationManager.AppSettings["connectionAWGDB"].ToString();
    SqlConnection connectionAWGDB = new SqlConnection(connectionString);
    return connectionAWGDB;
}catch(Exception exception){
        return   null;
}
}

private SqlCommand _getCommand(string sqlString, SqlConnection sqlConnection) //得到sql命令对象
{ </
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值