c# - SQL randomize rows and columns -
may know, how can randomize data gathered , randomize selected using sql integrate c# winform
for example
main content-----content1-----content2-----content3-----content4
to
main content-----content1-----content4-----content2-----content3
like multiple choice question, randomize question , choices. in advance.
edit:
this class.
public class qbank { string question, c1, c2, c3, c4, ans; public string ans { { return ans; } set { ans = value; } } public string c1 { { return c1; } set { c1 = value; } } public string c2 { { return c2; } set { c2 = value; } } public string c3 { { return c3; } set { c3 = value; } } public string c4 { { return c4; } set { c4 = value; } } public string question { { return question; } set { question = value; } }
this 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 want 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 topic selection?", "return", messageboxbuttons.yesno, messageboxicon.question, messageboxdefaultbutton.button2); if (dialog == dialogresult.yes) { frmpipe frm = new frmpipe(); frm.show(); hide(); } } int = 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()); } } }
im attaching pictures since there errors created list.
you can order rand() in mysql query:
example:
select * content order rand()
rand([n])
returns random floating-point value v in range 0 <= v < 1.0. obtain random integer r in range <= r < j, use expression floor(i + rand() * (j − i)).
Comments
Post a Comment