-1

I am getting an error when running the following code:

string SqlQuery = "Update " + frmmain.CityName + " set  assignedtouserid='" + 
frmmain.UserName + "', flag=1 where flag=0 and city like '%" + 
newcituname + "%' ";
LeptonDataLayer.ExecuteNoneQuery(1, SqlQuery);

This is the error I'm recieving:

Object reference not set to an instance of an object

What can i do to resolve it?

leppie
  • 115,091
  • 17
  • 196
  • 297

1 Answers1

0

frmmain or one of its fields are null (has not been assigned a new object) or LeptonDataLayer is null.

You need to figure out which one is null (use a debugger to find this out) and then make sure it has an appropriate value. Or don't run your query at all.

Also, I have to point out that generally building up T-SQL in code is a bad idea because it leaves you very vulnerable to Sql Injection attacks. You should be calling Stored Procedures and passing in Sql Parameters instead.

Philip Pittle
  • 11,821
  • 8
  • 59
  • 123