using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Data.SqlClient; namespace trial__ { public partial class Form1 : Form { public int incre = 1; public int b; public string y; public string z; public int marks; public Form1() { InitializeComponent(); radioButton1.TabStop = false; radioButton2.TabStop = false; radioButton3.TabStop = false; radioButton4.TabStop = false; marks = 0; } private void Form1_Load(object sender, EventArgs e) { // String Source = "xxxx"; SqlConnection con_2 = new SqlConnection(Source); { con_2.Open(); MessageBox.Show("connected to db"); string a = incre.ToString(); string sqlSelectQuery = @"SELECT *FROM [Table]"; SqlCommand cmd = new SqlCommand(sqlSelectQuery, con_2); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { label1.Text = (dr["ques"].ToString()); textBox1.Text = (dr["sl"].ToString()); radioButton1.Text = (dr["op A"].ToString()); radioButton2.Text = (dr["op B"].ToString()); radioButton3.Text = (dr["op C"].ToString()); radioButton4.Text = (dr["op D"].ToString()); } } con_2.Close(); } private void button2_Click(object sender, EventArgs e) { string a = incre.ToString(); String Source ="xxxx"; SqlConnection con_2 = new SqlConnection(Source); { con_2.Open(); string sqlSelectQuery = @"SELECT *FROM [Table] WHERE sL=" + a; SqlCommand cmd = new SqlCommand(sqlSelectQuery, con_2); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { label1.Text = (dr["ques"].ToString()); textBox1.Text = (dr["sl"].ToString()); radioButton1.Text = (dr["op A"].ToString()); radioButton2.Text = (dr["op B"].ToString()); radioButton3.Text = (dr["op C"].ToString()); radioButton4.Text = (dr["op D"].ToString()); if (radioButton1.Checked == true) { y = dr["ans"].ToString(); z = dr["marks"].ToString(); int bi = Convert.ToInt32(z); //ans.Text = "meg"; if (radioButton1.Text == y) { marks = marks +bi; } } if (radioButton2.Checked == true) { string g = (dr["ans"].ToString()); string h = dr["marks"].ToString(); int bd = Convert.ToInt32(h); if (radioButton2.Text == g) { marks = marks + bd; } } if (radioButton3.Checked == true) { string g = (dr["ans"].ToString()); string h = dr["marks"].ToString(); int bk = Convert.ToInt32(h); if (radioButton3.Text == g) { marks = marks + bk; } } if (radioButton4.Checked == true) { string g = (dr["ans"].ToString()); string h = dr["marks"].ToString(); int bl = Convert.ToInt32(h); if (radioButton4.Text == g) { marks = marks + bl; } } } } con_2.Close(); incre++; radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false;
string sqlSelectQuery = @"SELECT *FROM [Table] WHERE sL=" + a;
using (SqlCommand cmd = new SqlCommand("SELECT * FROM [Table] WHERE sL = @sL", con_2)) { cmd.Parameters.AddWithValue("@sL", incre); using (SqlDataReader dr = cmd.ExecuteReader()) { ... } }
public int incre { get { return (int?)ViewState["incre"] ?? 1; } set { ViewState["incre"] = value; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)