C# 文件上传总结

avatar
作者
猴君
阅读量:2
// 换成自己的数据 这要加一个转义字符 ​ 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("文件生成成功!");

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!