i am facing an error ("object refrence is not set to an instance of an object.") i check my all code but i can able to solve it . here is a line of code where i getting it.
cmd = new sqlcommand(_mycommand_)
serialNo = convert.ToInt16(cmd.executeScalar().toString());//----here i got an error
// as serialNo is a variable defined publicaly in my struct and datatype of it is int
please help me in this , so that i can move forword.
You need to make sure your command is actually returning some data. There is a pretty good chance that it isn't (hence the null reference exception caused by trying to convert a null reference to an int16).
If this is the case, I recommend checking for nulls and having a fall-back default value or some type of exception handling in place.
Instantiate your struct which has serial no as a variable and then access the serial number using the object of that struct. the struct has not been initialised, hence you are getting "object refrence is not set to an instance of an object." exception. try this out.