webapi

ajax直接请求后端需要写两个东西一个是跨域还有一个是支持text

img config.EnableCors(new EnableCorsAttribute("", "", "*"));

​ //支持text

​ config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain"));

img

这里必须stringf转

dataset直接显示绑定到datagridview需要指定0表格

DataSet list = bll.GetListByPage(where, "createTime desc", startIndex + 1, startIndex + 10);

gridView.DataSource = list; 为什么不显示

根据你提供的代码片段,我看到你在将 DataSet 对象赋值给 gridView.DataSource,但是没有指定要绑定的表格。

在这种情况下,DataSet 可能包含多个数据表,你需要明确指定要绑定的表格名称或索引。

假设你的 DataSet 中只有一个表格,你可以按照以下方式指定要绑定的表格:

gridView.DataSource = list.Tables[0]; // 假设表格的索引为 0
如果你的 DataSet 中有多个表格,你需要确认要绑定的表格的名称或索引。你可以使用 Tables 集合访问其中的表格,例如:

gridView.DataSource = list.Tables["TableName"]; // 替换为你要绑定的表格名称
此外,还需要确保在将数据源分配给 GridView 之后,调用 DataBind 方法来绑定数据并刷新显示:

gridView.DataBind(); // 绑定数据源并刷新显示
通过上述步骤,你应该能够将数据正确显示在 GridView 控件中了。如果问题仍然存在,请提供更多关于 GridView 控件的代码和更详细的问题描述,我将尽力帮助你解决问题。

链接字符串在webconfig中怎么写相对路径

在连接字符串中,数据源通常需要提供数据库的位置信息。对于使用相对路径的情况,要考虑到相对路径是相对于什么路径而言。

如果你想相对于应用程序的当前工作目录指定数据库位置,你可以使用 |DataDirectory| 占位符来表示应用程序的数据目录。具体到你的连接字符串中,可以这样写:

<add key="ConnectionString" value="Data Source=|DataDirectory|\YourDatabase.db" />
这样,数据库路径就会相对于应用程序的数据目录。在使用之前,确保你已经设置了合适的数据目录路径。

另外,如果你想使用相对于配置文件的路径来指定数据库位置,可以使用 ../ 这样的相对路径符号。例如,如果数据库文件与配置文件位于同一个目录下,可以这样写:

<add key="ConnectionString" value="Data Source=../YourDatabase.db" />
请根据你的实际情况选择适合的路径表示方法,确保能够正确找到数据库文件。
|DataDirectory| 默认会指向 App_Data 目录,该目录位于应用程序的根目录下。你可以将数据库文件放置在 App_Data 目录中,然后在连接字符串中使用 |DataDirectory|\YourDatabase.mdf 来指定数据库文件的位置。

sqllite中遇到的问题

sqllite中怎么做主键自增

取消unique not null 在pk(Primary Key)中添加Autoincrement

select * from diary

insert into diary values('2022-5-2','小雨','不开心')

一开始直接这样在sqlite expert中运行直接报错,两行不能同时处理

insert into diary values('2022-5-2','小雨','不开心')然后报错table diary has 4 columns but 3 values were supplied

我就好奇了,都自增了怎么还4 的column参数,搞了半天才知道

要加null才能主动默认

insert into diary values(null,'2022-5-2','小雨','不开心')

启动打不开

"F:\C#\培优礼堂票务管理系统\AuditoriumMS\DbTicketing.accdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

运行的any cpu 改成x86

异步方法转换

await 如果不支持的情况下,可以用下面的方法转换

Task t = Fi1e.ReadA11TextAsync(@"e: \templa\1.txt"");

string s = t.Resu1t;

Fi1e.ReadA11TextAsync(@"e: \templa\1.txt"").Wait() ; 风险:死锁

异步委托调用

异步委托
ThreadPoo1.QueueUserWorkitem(async(obj) =>{
await SomeAsync ();})

C#调用Python

            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = @"E:\pycharm\anaconda\python.exe"; // 指定Python解释器路径
            start.Arguments = @"E:\pythonProject1\pig\PigPrice.py"; // Python脚本的路径
            start.UseShellExecute = false;
            start.RedirectStandardOutput = true;
            // 检查Python解释器路径是否存在
            if (!System.IO.File.Exists(@"E:\pycharm\anaconda\python.exe"))
            {
                Console.WriteLine("Python解释器文件不存在!");
                return;
            }

            // 检查Python脚本路径是否存在
            if (!System.IO.File.Exists(@"E:\pythonProject1\pig\PigPrice.py"))
            {
                Console.WriteLine("Python脚本文件不存在!");
                return;
            }
            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string result = reader.ReadToEnd();
                    Console.WriteLine(result);
                }
            }
df.to_excel('caijipigprice.xlsx', index=False) 不指定路径 web调用同级 
# 假设 df 是你的 DataFrame 对象
# 你可以指定文件保存的完整路径,例如:
df.to_excel('E:/pythonProject1/pig/caijipigprice.xlsx', index=False)

是否连接网络

  • /// <summary>
    /// 关机
    /// </summary>
    public static void ShutDownWindows(int second)
    {
        var startInfo = new ProcessStartInfo("cmd.exe");
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardInput = true;
        startInfo.RedirectStandardOutput = true;
        startInfo.RedirectStandardError = true;
        startInfo.CreateNoWindow = true;
        var myProcess = new Process();
        myProcess.StartInfo = startInfo;
        myProcess.Start();
        myProcess.StandardInput.WriteLine("shutdown -s -t " + second);
    }
    

    ///

    /// 是否连接网络 /// /// public static bool NetworkIsLink() { Int32 flags = new int(); bool netWorkIsLink = InternetGetConnectedState(ref flags, 0); return netWorkIsLink; }

// 递归遍历控件并判断复选框的选中状态
                    private void CheckPanelCheckBoxes(Control control)
            {
                var flag = false;
                if (control is CheckBox)
                {
                    CheckBox checkBox = control as CheckBox;//将找到的control转化成checkbox
                    // 判断复选框的选中状态
                    if (checkBox.Checked)
                    {
                        // 复选框被选中
                        // 在这里执行你的逻辑操作
                        // 例如,可以输出复选框的名称
                        flag = true;
                        Console.WriteLine(checkBox.Name + " is checked.");
                    }
                    else
                    {
                        // 复选框未选中
                        // 在这里执行你的逻辑操作
                        // 例如,可以输出复选框的名称
                        Console.WriteLine(checkBox.Name + " is not checked.");
                    }
                }
                else if (control is Panel)
                {
                    // 遍历 Panel 控件的子控件
                    foreach (Control childControl in control.Controls)
                    {
                        // 递归调用 CheckPanelCheckBoxes 方法
                        CheckPanelCheckBoxes(childControl);
                    }
                }
            }
         // 调用 CheckPanelCheckBoxes 方法来处理窗体内的 Panel 控件
    foreach (Control control in this.Controls)
    {
        if (control is Panel)
        {
            Panel panel = control as Panel;//将找到的control转化成checkbox
            // 递归遍历 Panel 控件及其子控件
            CheckPanelCheckBoxes(panel);
        }
    }