Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have made the login page successfully. Now I have to fetch questions and options from database and display it in the form and it should contain buttons displaying the number of questions answered, unanswered, Total questions..The questions should be displayed one after the other when we click next..
My database contains Qid, Question, Option1, Option2, Option3, Option4 and Answer.

I want the code to perform this action so please kindly help me with this.....
Posted
Updated 5-Mar-14 11:05am
v2
Comments
OriginalGriff 5-Mar-14 15:00pm    
What have you tried?
Where are you stuck?
Sergey Alexandrovich Kryukov 5-Mar-14 15:02pm    
The post simply lacks subject. What do you mean "how"? By doing some software development work. Any real questions?
—SA
ZurdoDev 5-Mar-14 17:04pm    
The code will not exist until you write it. That's because we have no clue what your database fields are named, or your tables, or your SPs, or your page name or you controls. And also because you have not offered to pay anyone to do all this work for you.
BillWoodruff 5-Mar-14 20:56pm    
Try this to get some ideas:

http://www.codeproject.com/Answers/690265/Problem-to-get-property-value-from-user-Control-in
Ruth Priya 6-Mar-14 5:52am    
Ive tried. I have stored questions and options into the database. Now I'm trying to display the question into the form. But I ccant do it.....No errors ....but no changes in the form and the text box, label and radio buttons for options are empty.

The code that I've tried ios below....

Please help me with I have to do my project....There are still more....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace TypeA
{
public partial class q1 : Form
{

public q1()
{
InitializeComponent();
}

private void q1_Load(object sender, EventArgs e)
{
String con1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ruth Priya\Documents\q1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection con2 = new SqlConnection(con1);
int i = 1;
SqlCommand select = new SqlCommand("Select Questions from q1 where Qid = '" + i + "' ", con2);
SqlDataReader dr;
con2.Open();
dr = select.ExecuteReader();
dr.Read();

label1.Text = dr["Questions"].ToString();
dr.Close();
con2.Close();

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select Questions from q1 where Qid='" + i + "'", @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ruth Priya\Documents\q1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
da.Fill(ds);
if (ds.Tables[0].Rows.Count >= 0)
{
textBox1.Text = ds.Tables[0].Rows[0]["Qid"].ToString();

}

SqlConnection myConn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ruth Priya\Documents\q1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
myConn.Open();
SqlCommand myCommand = myConn.CreateCommand();

myCommand.CommandText = "select Questions from q1 where Qid = i ";

myCommand.CommandType = CommandType.Text;
SqlDataReader reader = myCommand.ExecuteReader();
DataTable dt2 = new DataTable();
dt2.Load(reader);

if (dt2.Rows.Count != 0)
{
label1.Text = dt2.Rows[0].ToString();



}



}




private void button1_Click(object sender, EventArgs e)
{
this.Hide();
q2 ss = new q2();
ss.Show();

}

private void label1_Click(object sender, EventArgs e)
{

}

private void textBox1_TextChanged(object sender, EventArgs e)
{
string myString = string.Empty;
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ruth Priya\Documents\q1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"))
{
string query = @"select Questions from q1 where Qid = i ";
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.Add("@Qid", SqlDbType.Int).Value = 1; //set your value

using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
myString += string.Format("Qid: {1}",
reader["Qid"].ToString()) + "\r\n";
}

label1.Text = "These are the results from the query:\r

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900