我有一个方法
Apr 23, 2016 9:23:04 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 23, 2016 9:23:05 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Apr 23, 2016 9:23:05 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'works'
Apr 23, 2016 9:23:05 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'works': initialization started
Apr 23, 2016 9:23:05 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'works-servlet': startup date [Sat Apr 23 21:23:05 MUT 2016]; root of context hierarchy
Apr 23, 2016 9:23:06 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/works-servlet.xml]
Apr 23, 2016 9:23:10 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'works': initialization completed in 5153 ms
Apr 23, 2016 9:23:10 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Apr 23, 2016 9:23:10 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Apr 23, 2016 9:23:10 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 12093 ms
我将此参数ID传递给另一个类
中的另一个函数getlisting(string url,int ID)
我将此传递给更新功能,并希望将默认值0分配给ID,将1分配给状态,然后将其返回并在数据库中进行更改,
Controller __cc = new Controller();
int Status = 1;
__cc.UpdatePaging(ID, Status);
但我不能这样做。我的代码有问题吗?或告诉我如何为int分配0值并在数据库中更新它,每当我从 public void UpdatePaging(int ID,int Status)
{
if (ID != null)
{
ID = 0;
}
else
{
ID = 0;
}
SqlCommand cmd = new SqlCommand("UPDATE Paging SET Status='1' WHERE ID = @ID", obj.openConnection());
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@Status", SqlDbType.Int).Value = 1;
cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
cmd.ExecuteNonQuery();
}
方法获得任何值时,它应该被指定为零并在DB中更新。
答案 0 :(得分:0)
基于聊天你想要这个:
public void UpdatePaging(int ID,int Status)
{
SqlCommand cmd = new SqlCommand("UPDATE Paging SET Status='1' WHERE ID = @ID", obj.openConnection());
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
cmd.ExecuteNonQuery();
}
这将根据发送到函数的id
将状态设置为1请注意,您的代码SET Status='1'
代表SET Status=1
您还可以使您的代码更加通用:
public void UpdatePaging(int ID,int Status=1)
{
SqlCommand cmd = new SqlCommand("UPDATE Paging SET Status=@Status WHERE ID = @ID", obj.openConnection());
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
cmd.Parameters.AddWithValue("@Status", SqlDbType.Int).Value = Status;
cmd.ExecuteNonQuery();
}