Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have following code




C#
string SqlQuery = "Update " + frmmain.CityName + " set  assignedtouserid='" + frmmain.UserName + "', flag=1 where flag=0 and city like '%" + newcituname + "%' ORDER BY LOCALITY DESC limit 100 ";
               LeptonDataLayer.ExecuteNoneQuery(1, SqlQuery);



but when i m run it it give following error like this

""Object reference not set to an instance of an object.""
Posted
Comments
PrakashCs.net 1-Aug-14 8:07am    
debug your code and check which property is null either 1.frmmain.CityName 2.frmmain.UserName 3.newcituname or LeptonDataLayer

1 solution

First remove order by and limit from update query, There is nothing need of it and it never works also.

C#
SqlConnection cn = new SqlConnection("ConnectionString");
           string SqlQuery = "Update tableName set  assignedtouserid='" + frmmain.UserName + "', flag=1 where flag=0 and city like '%" + newcituname + "%'";
           SqlCommand cmd = new SqlCommand(SqlQuery, cn);
           cn.Open();
           cmd.ExecuteNonQuery();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900