Sadhana

Sadhana

  • NA
  • 14
  • 2.3k

In my code variable i is not increamenting second time.

Apr 19 2015 3:16 AM
here in button_3 click variable i is increamenting only once.then it enters the loop but i is not increamenting.i again takes the value 0. 
 
 
 
 
 
 
 
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Drawing.Design;
using System.Xml.Linq;
using System.Linq;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic;
public partial class DeptMarks : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
SqlCommand cmd = new SqlCommand();
SqlDataReader dr,dr1;
DataSet ds;
DataTable dt;
BindingSource bs = new BindingSource();
int i;
int count;
int j=1;
public void Page_Load(object sender, EventArgs e)
{
ds = new DataSet();
con.Open();
cmd.Connection = con;
dt = new DataTable();
TextBox79.Visible = false;
cmd.CommandText = "select [USN] from Course_reg where Semester='" + TextBox1.Text + "' and Year='" + TextBox80.Text + "'";
SqlDataAdapter da = new SqlDataAdapter(cmd);
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
// DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Visible = false;
GridView1.DataSource = ds.Tables["Course_reg"];
if (ds.Tables[0].Rows.Count > 0)
{
i = 0;
MessageBox.Show("i3" + i);
TextBox2.Text = ds.Tables[0].Rows[i]["USN"].ToString();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
// DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
// bs.DataSource = ds.Tables["Course_reg"];
count = GridView1.Rows.Count;
MessageBox.Show("gg"+count);
GridView1.DataBind();
GridView1.Visible = false;
GridView1.DataSource = ds.Tables["Course_reg"];
if (!string.IsNullOrEmpty(TextBox44.Text))
{
string user1 = Session["user1"].ToString();
TextBox79.Text = user1;
cmd.CommandText = "select * FROM Subject where Sub_Code='" + TextBox44.Text + "' and Semester='" + TextBox1.Text + "'";
string subcode = (string)cmd.ExecuteScalar();
if (!string.IsNullOrEmpty(subcode))
{
if (DropDownList2.Text == "CAT-1")
{
int m1 = Convert.ToInt32(TextBox41.Text);
if (m1 >= 0 && m1 <= 20)
{
cmd.CommandText = "INSERT INTO Student_marks VALUES('" + TextBox1.Text +
"','" + TextBox80.Text +
"','" + TextBox2.Text +
"','" + TextBox44.Text +
"','" + TextBox41.Text +
"','" + "','" + "','" + "','" + "','" + TextBox79.Text + "')";
cmd.ExecuteNonQuery();
}
else
{
Label2.Text = "Marks should be in the range of 0-20";
Label2.Visible = true;
}
}
if (DropDownList2.Text == "CAT-2")
{
int m2 = Convert.ToInt16(TextBox41.Text);
if (m2 >= 0 && m2 <= 20)
{
cmd.CommandText = "update Student_marks set CAT_2='" + TextBox41.Text + "' where USN='" + TextBox2.Text + "'and Semester='" + TextBox1.Text + "' and Subject_code='" + TextBox44.Text + "'";
cmd.ExecuteNonQuery();
}
else
{
Label2.Text = "Marks should be in the range of 0-20";
Label2.Visible = true;
}
}
if (DropDownList2.Text == "Makeup")
{
int m3 = Convert.ToInt16(TextBox41.Text);
if (m3 >= 0 && m3 <= 20)
{
cmd.CommandText = "update Student_marks set CAT_3='" + TextBox41.Text + "' where USN='" + TextBox2.Text + "'and Semester='" + TextBox1.Text + "' and Subject_code='" + TextBox44.Text + "'";
cmd.ExecuteNonQuery();
}
else
{
Label2.Text = "Marks should be in the range of 0-20";
Label2.Visible = true;
}
}
if (DropDownList2.Text == "CAM")
{
int m4 = Convert.ToInt16(TextBox41.Text);
if (m4 >= 0 && m4 <= 10)
{
cmd.CommandText = "update Student_marks set CAM='" + TextBox41.Text + "' where USN='" + TextBox2.Text + "'and Semester='" + TextBox1.Text + "' and Subject_code='" + TextBox44.Text + "'";
cmd.ExecuteNonQuery();
}
else
{
Label2.Text = "Marks should be in the range of 0-10";
Label2.Visible = true;
}
}
if (DropDownList2.Text == "ESE")
{
Int32 mr1, mr2, mr3, mr4, mr5, b1 = 0, b2 = 0, cat = 0, ese = 0, total = 0;
int m5 = Convert.ToInt16(TextBox41.Text);
if (m5 >= 0 && m5 <= 100)
{
cmd.CommandText = "update Student_marks set ESE='" + TextBox41.Text + "' where USN='" + TextBox2.Text + "'and Semester='" + TextBox1.Text + "' and Subject_code='" + TextBox44.Text + "'";
cmd.ExecuteNonQuery();
}
else
{
Label2.Text = "Marks should be in the range of 0-100";
Label2.Visible = true;
}
cmd.CommandText = "select * from Student_marks where usn='" + TextBox2.Text + "'";
dr = cmd.ExecuteReader();
dr.Read();
mr1 = int.Parse(dr[4].ToString());
mr2 = int.Parse(dr[5].ToString());
mr3 = int.Parse(dr[6].ToString());
mr4 = int.Parse(dr[7].ToString());
mr5 = int.Parse(dr[8].ToString());
if (mr1 <= mr2 && mr1 <= mr3)
{
b1 = mr2;
b2 = mr3;
}
else if (mr2 <= mr1 && mr2 <= mr3)
{
b1 = mr1;
b2 = mr3;
}
else if (mr3 <= mr1 && mr3 <= mr2)
{
b1 = mr1;
b2 = mr2;
}
cat = b1 + b2 + mr4;
TextBox81.Text = cat.ToString();
ese = (mr5 / 2);
TextBox82.Text = ese.ToString();
total = cat + ese;
TextBox83.Text = total.ToString();
cmd.CommandText = "insert into Final_marks values ('" + TextBox2.Text + "','" + TextBox1.Text + "','" + TextBox44.Text + "','" + TextBox81.Text + "','" + TextBox82.Text + "','" + TextBox83.Text + "','" + "')";
dr.Close();
cmd.ExecuteNonQuery();
// MessageBox.Show("hui");
//cmd.CommandText = "select * from Student_marks where usn='" + TextBox2.Text + "'";
//dr = cmd.ExecuteReader();
}
}
else
{
Label1.Text = "This subject is not registered for this semester";
Label1.Visible = true;
}
}
if (i < count)
{
i++;
TextBox2.Text = ds.Tables[0].Rows[i]["USN"].ToString();
}
if (i == count)
{
Label1.Text = "this is the last record";
Label1.Visible = true;
}
}
}

Answers (4)