小编Sal*_*ari的帖子

CheckBox CheckChanged事件

之后Checkbox.IsChecked = true,Checked事件被触发.之后Checkbox.IsChecked = false,UnChecked事件被触发.但之后发生了什么事IsChecked = null

.net c# wpf checkbox events

5
推荐指数
1
解决办法
169
查看次数

使用System.Data.Linq.Mapping并在sqlite db中自动递增主键时出错

我正在使用SQLiteSystem.Data.Linq.Mapping.id AUTOINCREMENT使用linq mapping属性时,我遇到了该字段的问题IsDbGenerated = true.

创建表的语法.我已经尝试了这个/没有AUTOINCREMENT

CREATE TABLE [TestTable] ([id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,[title] TEXT  NULL)
Run Code Online (Sandbox Code Playgroud)

我的TABLE类:

[Table(Name = "TestTable")]
public class TestTable
{
    [Column(IsPrimaryKey = true, IsDbGenerated =true)]
    public int id { get; set; }

    [Column]
    public string title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我如何称呼它.当它提交我得到一个错误,我将粘贴此示例下面的错误.需要注意的一件事是,如果我拿出IsDbGenerated =true上面的内容并id手动输入它确实插入正常,但我喜欢它,AUTOINCREMENT并且由于某种原因,它IsDbGenerated=true正在杀死插入物.寻求一些指导.

static void Main(string[] args)
{
    string connectionString = @"DbLinqProvider=Sqlite;Data Source = c:\pathToDB\test.s3db";
    SQLiteConnection connection …
Run Code Online (Sandbox Code Playgroud)

c# sql linq sqlite system.data.sqlite

5
推荐指数
1
解决办法
2550
查看次数

使用while将字符串分成两个单词

string givenstring,outputString="";
int i, j = 0;
Console.WriteLine("Enter the string");
givenstring = Console.ReadLine();
i = (givenstring.Length) / 2;

while (j < i)
{
    outputString += givenstring[j];
    j++;
}

Console.WriteLine(outputString);
outputString = string.Empty;

while (i < givenstring.Length)
{
    outputString += givenstring[i];
    i++;
}
Console.WriteLine(outputString);
Run Code Online (Sandbox Code Playgroud)

在这里,我将字符串分成两个字符串.例如,输入:

你好,世界

输出:

你好,世界.

但现在我需要输出:

dlrow olleH

.net c# string console-application

5
推荐指数
1
解决办法
438
查看次数

使用实体框架从存储过程中检索表数据

我正在使用Entity Framework v6.我有一个存储过程,如下所示

CREATE PROCEDURE [dbo].[GetCountryList] 
(
    @CustomerName VARCHAR(MAX), 
    @SearchCriteria VARCHAR(MAX)
)
AS
    BEGIN
    SET NOCOUNT ON

        SELECT CountryID, CountryName FROM dbo.Table1 
        WHERE CustomerName = @CustomerName AND CountryName = @SearchCriteria
    END
Run Code Online (Sandbox Code Playgroud)

现在我有一个模型类

public class CountryName
{
    public int CountryId { get; set; }
    public string CountryName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

所以我想SELECT在一个List<CountryName>类型中获得查询的结果

List<CountryName> countryList = null;

using (DbEntities dbContext = new DbEntities())
{
    countryList = //my code to collect the result
}
Run Code Online (Sandbox Code Playgroud)

好吧,我可以直接在表上运行LINQ to SQL,但不幸的是我要求从存储过程中获取数据.那么,我该怎么做呢?

c# sql-server stored-procedures entity-framework entity-framework-6

5
推荐指数
2
解决办法
1万
查看次数

如何阅读文本框中的最后一行?

我有一个不断更新的多行文本框.我只需要阅读文本框中的最后一个单词/句子.

string lastLine = textBox1.ReadLine.Last();
Run Code Online (Sandbox Code Playgroud)

c# linq string textbox readlines

5
推荐指数
1
解决办法
5038
查看次数

一个aspx页面有utf-8编码

如何将一个aspx页面更改为utf-8编码?

我的web.config有以下代码:

<system.web>
  <globalization
     requestEncoding="utf-8"
     responseEncoding="utf-8"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)

试过这个:

meta http-equiv="Content-Type" content="text/html; charset=UTF-8" 
Run Code Online (Sandbox Code Playgroud)

不起作用.

c# vb.net asp.net utf-8

5
推荐指数
1
解决办法
1万
查看次数

应用关闭时运行的代码

我发现了很多编写代码的例子,这些代码在WPF或Windows Forms应用程序终止时执行,但不适用于UWP应用程序.是否有可以覆盖的特殊C#方法,或者可以用来包含清理代码的事件处理程序?

这是我尝试的WPF代码,但在我的UWP应用程序中不起作用:

App.xaml.cs (没有样板用法和名称空间声明)

public partial class App : Application
{
        void App_SessionEnding(object sender, SessionEndingCancelEventArgs e)
        {
            MessageBox.Show("Sorry, you cannot log off while this app is running");
            e.Cancel = true;
        }
}
Run Code Online (Sandbox Code Playgroud)

App.xaml中

<Application x:Class="SafeShutdownWPF.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:SafeShutdownWPF"
             StartupUri="MainWindow.xaml"
             SessionEnding="App_SessionEnding">
    <Application.Resources>

    </Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)

我尝试使用Process.Exited,但VS2015无法识别内部的进程System.Diagnostics.

c# win-universal-app

5
推荐指数
1
解决办法
903
查看次数

检查DatePicker值是否为null

我想检查a的值DatePicker是否为null(==框中没有日期).

默认情况下Text,我DatePicker的设置为类似Select a date,所以我无法使用该Text属性进行检查.

c# wpf datepicker wpf-controls

5
推荐指数
1
解决办法
2万
查看次数

使用自动增量插入

我正在尝试将一些数据插入到我的 SQLite 数据库中,当我使用一条记录执行此操作时,它可以完美地工作。但是在循环中我得到一个错误。首先,这是代码

string dataSource = "Data Source=";
Connection = new SQLiteConnection(dataSource + this.DatabasePath);

var context = new DataContext(Connection);

var users = context.GetTable<User>();


for (int i = 0; i < 2; i++) {
    User tempUser = new User() {
        ID = null,
        EMail = i + "@" + i + ".de",
        Password = "Test1234",
        JoinedDate = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")
    };

    users.InsertOnSubmit(tempUser);
    context.SubmitChanges();
}
Run Code Online (Sandbox Code Playgroud)

和用户本身

[Table(Name = "User")]
public class User {

    [Column(Name = "UserID", IsPrimaryKey = true, CanBeNull = false)]
    public …
Run Code Online (Sandbox Code Playgroud)

c# linq sqlite

5
推荐指数
1
解决办法
2010
查看次数

无法从任务列表中获取结果

我有这个async函数返回一个Task

public async Task<SettingModel> GetSetting(string key)
{
    var rootPath = _hostingEnvironment.ContentRootPath;
    using (StreamReader r = new StreamReader(rootPath + key + "settings.json"))
    {
        string json = await r.ReadToEndAsync();
        var settings = JsonConvert.DeserializeObject<SettingModel>(json);
        return settings;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我想获得所有设置,然后等到所有设置完成后才这样

public async Task GetData(List<string> keys)
{
    var taskList = new List<Task>();
    foreach(var key in keys)
    {
        taskList.Add(GetSetting(key));
    }

    await Task.WhenAll(taskList.ToList());

    foreach (var task in taskList)
    {
        task.Result // here its not working. The task don't have a result :(
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# async-await

5
推荐指数
1
解决办法
1751
查看次数