Shah Rukh Shah Rukh - 10 months ago 22
SQL Question

Assign a default value for every coming int in the method

i have two methods having

getlisting(string url,int ID)

i want to pass this ID to another method in another class,

class cc=new class();

now i want to pass this int value to that updatevalue method and assign it a 0 value. and every time getlisting having different ID and passing it to update method. i have tried if else condition as well. so my question is can anyone help me in assigning that default 0 value to every coming int value.
after assigning i want to update that in my DataTable

SqlCommand cmd = new SqlCommand("UPDATE Paging SET Status='1' WHERE ID ='ID'", obj.openConnection());

and ID is throwing an error of cannot convert varchar into data type, tell me the condition with which i can give default value to every int and makes it equal to ID. thanks


I suspect the problem is with your SQL, also I suggest using parameterized query , so your code should be...

SqlCommand cmd = new SqlCommand("UPDATE Paging SET Status=@status WHERE ID =@id", obj.openConnection());

cmd.Parameters.Add("@status", SqlDbType.Int).Value = 1; // modify this to varchar if status is string
cmd.Parameters.Add("@id", SqlDbType.Int).Value = ID;

On the side note, we could specify default value for parameters take a look at Named and Optional Arguments.