我可以知道,如何使用SQL将收集到的数据随机化并将选定的数据随机化
我会把它集成到c#winform
例如
主要内容——内容1——内容2——内容3——内容4

主要内容---content1--content4--content2--content3
像多项选择题一样,随机化问题及其选择。提前谢谢。
编辑:
这是我的课。

public class qbank
{
    string question, c1, c2, c3, c4, ans;

    public string Ans
    {
        get { return ans; }
        set { ans = value; }
    }

    public string C1
    {
        get { return c1; }
        set { c1 = value; }
    }

    public string C2
    {
        get { return c2; }
        set { c2 = value; }
    }

    public string C3
    {
        get { return c3; }
        set { c3 = value; }
    }

    public string C4
    {
        get { return c4; }
        set { c4 = value; }
    }

    public string Question
    {
        get { return question; }
        set { question = value; }
    }

这是我的winform
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace frmMain
{
    public partial class frmPIPETest : Form
    {
        string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;
        Data Source=C:\Users\rehpe\Documents\Visual Studio 2015\Projects\panibago\questionbank.accdb;
        Persist Security Info=False";
        string query = "";
        OleDbConnection conn = null;

        public frmPIPETest()
        {
            InitializeComponent();
        }

        private void frmPIPETest_FormClosing(object sender, FormClosingEventArgs e)
        {
            System.Media.SystemSounds.Beep.Play();
            DialogResult dialog = MessageBox.Show("Do you really want to exit?",
                                  "Exit Program",
                                  MessageBoxButtons.YesNo,
                                  MessageBoxIcon.Question,
                                  MessageBoxDefaultButton.Button2);
            if (dialog == DialogResult.Yes)
            {
                Application.ExitThread();
            }
            else
            {
                e.Cancel = true;
            }
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            System.Media.SystemSounds.Beep.Play();
            DialogResult dialog = MessageBox.Show("Go back to topic selection?",
                                  "Return",
                                  MessageBoxButtons.YesNo,
                                  MessageBoxIcon.Question,
                                  MessageBoxDefaultButton.Button2);
            if (dialog == DialogResult.Yes)
            {
                frmPIPE frm = new frmPIPE();
                frm.Show();
                Hide();
            }
        }

        int i = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            i++;
            lblTimer.Text = i.ToString() + "s";
        }

        public qbank()
        {
            IEnumerable<qbank> content = new List<qbank>
            var random = new Random();
            var result = content
                .Select(c =>
                {
                    var strings = new[]
                    {
                        c.C1,
                        c.C2,
                        c.C3,
                        c.C4,
                    }.OrderBy(x => random.Next())
                    .ToArray();
                    return new qbank
                    {
                        Question = c.Question,
                        C1 = strings[0],
                        C2 = strings[1],
                        C3 = strings[2],
                        C4 = strings[3],
                    };
                })
            .OrderBy(x => random.Next());
        }
    }
}

我正在附加图片,因为我创建列表的地方有错误。
Expected Interface

最佳答案

您可以在mysql查询中按rand()排序:
例子:

SELECT * FROM content ORDER BY rand()

兰特([N])
返回0获取i地板(i+RAND()*(j-i))。

关于c# - SQL随机化行和列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46139771/

10-10 03:16