Code:
string cat = Request.QueryString[
"NullReferenceE xception code Unhandlled by user code"
Please reply.........
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class update : System.Web.UI.Page
{
private SqlConnection scon;
private SqlCommand cmd;
private SqlDataReader dr;
int cid;
string select;
string u;
protected void Page_Load(object sender, EventArgs e)
{
scon = new SqlConnection("Data Source=.\\Sqlexpress;initial catalog =BDB;integrated security =true");
scon.Open();
string cat = Request.QueryString["catid"].ToString();
cid = Convert.ToInt32(cat);
if (cid == 1 | cid == 2 | cid == 3)
{
select = "select * from computer_education where category_id=" + cid;
}
if (cid == 4 | cid == 5 | cid == 6)
{
select = "select * from children_books where category_id=" + cid;
}
if (cid == 7 | cid == 8)
{
select = "select * from cooking where category_id=" + cid;
}
if (cid == 11 | cid == 12 | cid == 13)
{
select = "select * from religion where category_id=" + cid;
}
if (cid == 18 | cid == 19 | cid == 20)
{
select = "select * from Entertainment where category_id=" + cid;
}
if (cid == 21 | cid == 22)
{
select = "select * from science where category_id=" + cid;
}
if (cid == 23 | cid == 24)
{
select = "select * from Business_investing where category_id=" + cid;
}
cmd = new SqlCommand(select, scon);
dr = cmd.ExecuteReader();
while (dr.Read())
{
ListItem newitem = new ListItem();
newitem.Text = dr["book_name"].ToString();
newitem.Value = dr["item_id"].ToString();
DropDownList2.Items.Add(newitem);
}
dr.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (cid == 1 | cid == 2 | cid == 3)
{
u = "update computer_education set price=@price where item_id=@item_id";
}
if (cid == 4 | cid == 5 | cid == 6)
{
u = "update children_books set price=@price where item_id=@item_id";
}
if (cid == 7 | cid == 8 )
{
u = "update cooking set price=@price where item_id=@item_id";
}
if (cid == 11 | cid == 12 | cid == 13)
{
u = "update religion set price=@price where item_id=@item_id";
}
if (cid == 18 | cid == 19 | cid == 20)
{
u = "update Entertainment set price=@price where item_id=@item_id";
}
if (cid == 21 | cid == 22)
{
u = "update science set price=@price where item_id=@item_id";
}
if (cid == 23 | cid == 24)
{
u = "update Business_investing set price=@price where item_id=@item_id";
}
cmd = new SqlCommand(u, scon);
cmd.Parameters.AddWithValue("@price", Decimal.Parse(TextBox6.Text));
cmd.Parameters.AddWithValue("@item_id", DropDownList2.SelectedItem.Value);
cmd.ExecuteNonQuery();
Label24.Visible = true;
Label24.Text = "Price Updated Successfully";
}
catch (Exception err)
{
Label24.Visible = true;
Label24.Text = "Not updated" + err.Message.ToString();
}
}
}
Comment