C# 文件上传总结

// 换成自己的数据 这要加一个转义字符
​
SQL Server 2008 支持两种登录模式:混合模式(Mixed Authentication)和 Windows 身份验证模式(Windows Authentication Mode)。
​
混合模式:在混合模式下,SQL Server 身份验证和 Windows 身份验证都是支持的。在这种模式下,用户可以使用 SQL Server 登录名(用户名和密码)进行登录,也可以使用 Windows 用户帐户进行登录。
​
Windows 身份验证模式:在这种模式下,只能使用 Windows 的登录凭证进行登录。当使用 Windows 身份验证时,用户的登录名和密码不再由 SQL Server 管理,而是由 Windows 的身份验证服务(如 Active Directory)管理。
​
要更改登录模式,您可以使用 SQL Server Management Studio (SSMS) 或使用 T-SQL 命令。
​
 private string connectionString = "Data Source=MOGFPLQEEJOTGON\\SQLEXPRESS;Initial            Catalog=hm_dataaccess;User ID=frank;Password=root123";
 
DatabaseAccess类是干嘛的
// 查询数据库中的数据将其添加到具体的集合里面
class DatabaseAccess
    {
 public List<T> GetCollectionByField<T>(string connectionString, string sql, Func<SqlDataReader, T> mapFunction ,string value)
        {
            var results = new List<T>();
   using (var connection = new SqlConnection(connectionString)) // 要连接的数据库
   {
    using (var command = new SqlCommand(sql, connection)) // 创建执行终端
       {
        command.Parameters.AddWithValue("@value", value); //sql语句要添加相应的参数
        connection.Open(); // 打开连接
        using (SqlDataReader reader = command.ExecuteReader()) //读取数据库里面的数据
        {
            while (reader.Read())
            {
            // 将一条数据添加到集合里面
            results.Add(mapFunction(reader));
            }
        }
                }
            }
            return results;
        }
    }
try
{
    //将字符串转化成Datetime 类型的数据
    dateValue = DateTime.Parse(value);
}
catch (FormatException)
{
    Console.WriteLine("字符串格式不正确,无法转换。");
}
// 将 Datetime 转化为指定的字符串格式的数据
string dateString = dateValue.ToString("yyyyMMddHHmmss");
// 获取指定路径
var directory = Path.GetDirectoryName(filePath);
// 如果没有目录就重新生成一个
if (!Directory.Exists(directory))
{
    // 创建一个文件
    Directory.CreateDirectory(directory);
}
// 写入文件
File.WriteAllText(filePath, fileContent);
MessageBox.Show("文件生成成功!");
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值