my que is i have used this code for retriving data from grid view and insert it into database.now at the button event the values are not retrived from the gridview.it gives error Object reference not set to an instance of an object.wht is soln? - public partial class frmshowcustapp : System.Web.UI.Page
-
{
-
public SqlCommand cmd;
-
public string str;
-
public SqlDataAdapter dtp;
-
public DataSet ds;
-
public SqlDataReader dr;
-
public string id, birthday, c_name,phone_no, address, l_or_pno, emailid, city, pincode, occuption,photo,imagpath,dealer_list, sex, f_member;
-
//"id","c_name","birthday","phone_no","address","l_or_pno","emailid","city","pincode""occuptiopn","sex","f_member");
-
// public partial class migrated_frmshowcustapp:frmshowcustapp
-
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
if (!IsPostBack)
-
connection.getconn();
-
//Panel1.Visible = false;
-
}
-
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
//Panel1.Visible = true;
-
-
id = GridView1.SelectedRow.Cells[1].Text;
-
-
c_name = GridView1.SelectedRow.Cells[2].Text;
-
birthday = GridView1.SelectedRow.Cells[3].Text;
-
phone_no = GridView1.SelectedRow.Cells[4].Text;
-
address = GridView1.SelectedRow.Cells[5].Text;
-
photo = GridView1.SelectedRow.Cells[15].Text;
-
imagpath = GridView1.SelectedRow.Cells[6].Text;
-
l_or_pno = GridView1.SelectedRow.Cells[7].Text;
-
emailid = GridView1.SelectedRow.Cells[8].Text;
-
city = GridView1.SelectedRow.Cells[9].Text;
-
pincode = GridView1.SelectedRow.Cells[10].Text;
-
occuption = GridView1.SelectedRow.Cells[13].Text;
-
sex = GridView1.SelectedRow.Cells[11].Text;
-
f_member = GridView1.SelectedRow.Cells[12].Text;
-
dealer_list = GridView1.SelectedRow.Cells[14].Text;
-
txtemailid.Text = GridView1.SelectedRow.Cells[8].Text;
-
txtcname.Text = GridView1.SelectedRow.Cells[2].Text;
-
-
}
-
-
protected void btnsavec_Click(object sender,EventArgs e)
-
{
-
-
id = GridView1.SelectedRow.Cells[1].Text;
-
-
c_name = GridView1.SelectedRow.Cells[2].Text;
-
birthday = GridView1.SelectedRow.Cells[3].Text;
-
phone_no = GridView1.SelectedRow.Cells[4].Text;
-
address = GridView1.SelectedRow.Cells[5].Text;
-
photo = GridView1.SelectedRow.Cells[15].Text;
-
imagpath = GridView1.SelectedRow.Cells[6].Text;
-
l_or_pno = GridView1.SelectedRow.Cells[7].Text;
-
emailid = GridView1.SelectedRow.Cells[8].Text;
-
city = GridView1.SelectedRow.Cells[9].Text;
-
pincode = GridView1.SelectedRow.Cells[10].Text;
-
occuption = GridView1.SelectedRow.Cells[13].Text;
-
sex = GridView1.SelectedRow.Cells[11].Text;
-
f_member = GridView1.SelectedRow.Cells[12].Text;
-
dealer_list = GridView1.SelectedRow.Cells[14].Text;
-
txtemailid.Text = GridView1.SelectedRow.Cells[8].Text;
-
txtcname.Text = GridView1.SelectedRow.Cells[2].Text;
-
-
-
str="insert into customer_list values('" + id +"','"+ c_name +"','" + birthday +"','"+phone_no+"','"+address+"','"+photo+"','"+imagpath+"','"+l_or_pno+"','"+emailid+"','"+city+"','"+pincode+"','"+occuption+"','"+sex+"','"+f_member+"','"+dealer_list+"','"+txtid.Text+"')";
-
cmd = new SqlCommand(str,connection.conn);
-
cmd.ExecuteNonQuery();
-
lblmsg.Text = "done";
-
-
}
2 1128
I don't see connection defined anywhere.
whenever u r accessing any object, make sure that object is not null. For this u always can check with conditional statement and write ur executing that code if object not null condition is true.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pkpatel |
last post by:
Hi,
I keep getting this error every time I try to load
crystalreportviewer on a webform with a dataset.
Here is the error:
--------------------------------------------------------
Server...
|
by: NewToDotNet |
last post by:
I am getting "Object reference not set to an instance of an object. " when I
attempt to open a C# windows service class in design view, although I was
able to initially create the service and open...
|
by: Frawls |
last post by:
Hi,
I get the following error when trying to run a search on my aspx site,
this error only occours if the product im searching for does not
exist. Can anybody explain this please and help me...
|
by: jw56578 |
last post by:
why am i getting the "Object reference not set to an instance of an
object" error on all page registeration tags in my project.
<%@ Page Language="vb" AutoEventWireup="false"...
|
by: nemo |
last post by:
Hi,
My application works fine on the localhost but spits this error as soon
as I put it on the server. I know this error occurs when an object has
not been instantiated prior to a reference, but...
|
by: Adam |
last post by:
We have a web site that uses .vb for the web pages and .cs for a class
module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does
work with .NET 1.1.
When trying to access a page...
|
by: Brett |
last post by:
I'm not sure why I keep getting this error, "Object reference not set to an
instance of an object".
Private Function somefunction() as string
Dim MyCurrentClass As New Class1
Try
For i As...
|
by: kalaivanan |
last post by:
hi,
i am a beginner in c#.
i have theoretical knowledge about object, reference and instance.
but i want to know clearly about what is an object, reference and
instance.
can any one help me?
or...
|
by: vishnu |
last post by:
Hi,
I am working on asp.net project which I converted the code fron VB
to C# and instead of RaiseEvent in VB code I used the following code.
using System;
using System.Data;
using...
|
by: livmacca |
last post by:
Hi,
I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work:
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |