TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jujur Soaloon Sitanggang
NA
32
1.3k
Get a data random from mysql using C#
Jan 11 2017 12:51 PM
hello master
a have a problem to get a data from mysql
i have a database like this
idquestion || question || optiona || optionb || optionc || optiond || answer
i try to get a random data from mysql to From in c#
this my code to get a data from mysql
private
DataTable tquestion;
public
string
ide =
""
;
public
string
soale=
""
;
public
string
ae=
""
;
public
string
be=
""
;
public
string
ce=
""
;
public
string
de=
""
;
public
string
je=
""
;
public
string
NISe;
public
void
getdata()
{
ide = tquestion.Rows[0].ItemArray[0].ToString();
soale = tquestion.Rows[0].ItemArray[1].ToString();
ae = tquestion.Rows[0].ItemArray[1].ToString();
be = tquestion.Rows[0].ItemArray[2].ToString();
ce = tquestion.Rows[0].ItemArray[3].ToString();
de = tquestion.Rows[0].ItemArray[4].ToString();
sql =
"SELECT * FROM question ORDER BY RAND() LIMIT 1"
;
tquestion = koneksi.tampil_data(sql);
textBox1.Text = soale;
rbA.Text = ae;
rbB.Text = be;
rbC.Text = ce;
rbD.Text = de;
}
this the erorr form c#
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not
set
to an instance of an
object
.
Source=sistem_basis_data
StackTrace:
at sistem_basis_data.home.ambilsoal()
in
c:\Users\Asus\Documents\client\sistem_basis_data24\sistem_basis_data\sistem_basis_data\home\home.cs:line 83
at sistem_basis_data.home.home_Load(Object sender, EventArgs e)
in
c:\Users\Asus\Documents\client\sistem_basis_data24\sistem_basis_data\sistem_basis_data\home\home.cs:line 70
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
InnerException:
Reply
Answers (
3
)
Unable to convert MySQL date/time value to System.DateTime
How automatically calculate days then delete files c#?