2014-01-26 133 views
0

我有以下的Web方法的代碼檢索以下:SQL Server數據庫查詢web服務

[WebMethod] 
public List<Hawker> retrievehawker() 
{ 
    List<Hawker> retrievehawker = new List<Hawker>(); 

    string qry = @"select hawkername, address, postal, xcoord, ycoord, popularity from uploadphoto"; 

    SqlConnection conn = new SqlConnection(connString); 
    SqlCommand cmd = conn.CreateCommand(); 
    cmd.CommandText = qry; 

    conn.Open(); 
    SqlDataReader mySqlDataReader = cmd.ExecuteReader(); 
    while (mySqlDataReader.Read()) 
    { 
     Hawker retrieveHawker = new Hawker(); 
     retrieveHawker.hawkername = Convert.ToString(mySqlDataReader["hawkername"]); 
     retrieveHawker.address = Convert.ToString(mySqlDataReader["address"]); 
     retrieveHawker.postal = Convert.ToString(mySqlDataReader["postal"]); 
     retrieveHawker.xcoord = Convert.ToDouble(mySqlDataReader["xcoord"]); 
     retrieveHawker.ycoord = Convert.ToDouble(mySqlDataReader["ycoord"]); 
     retrieveHawker.popularity = Convert.ToDouble(mySqlDataReader["popularity"]); 


     retrievehawker.Add(retrieveHawker); 
    } 
    mySqlDataReader.Close(); 
    conn.Close(); 
    return retrievehawker; 
} 

如何更改代碼,以便每當這個方法是由我的Windows手機引發的,它會插入+1到人氣的價值?

回答

0

,請撥打以下方法來更新普及

int SetPopularity() 
{ 
    string qry = @"update uploadphoto set popularity=popularity+1";  
    SqlConnection conn = new SqlConnection(connString); 
    SqlCommand cmd = conn.CreateCommand(qry,con); 
    conn.Open(); 
    int status=cmd.ExecuteNonQuery(); 
    conn.Close(); 
    return status; 
} 
+0

我怎麼能說我的檢索小販這裏面的方法?我必須根據選擇,並執行更新 – NoobieNeedHelp

+0

如果可能的話,看看這個問題我問http://stackoverflow.com/questions/21362197/sql-server-retrieve-and-update-windows-phone-7 – NoobieNeedHelp

相關問題