title: C# Parsing Return Data into JSON
body: <p>I am having some problem when trying to parse the return data into JSON in C#. So basically I have an example which is in SELECT SQL statement:</p>
  
  <pre><code>[WebMethod]
  public string getUserDetails(string userID)
  {
      DataTable dt = new DataTable();
      SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnStr"].ConnectionString);
      string select = "select * from dbo.User WHERE userID = '" + userID + "'";
      sqlConnection.Open();
      SqlDataAdapter da = new SqlDataAdapter(select, sqlConnection);
      da.Fill(dt);
      System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
      List&lt;Dictionary&lt;string, object&gt;&gt; rows = new List&lt;Dictionary&lt;string, object&gt;&gt;();
      Dictionary&lt;string, object&gt; row;
      foreach (DataRow dr in dt.Rows)
      {
          row = new Dictionary&lt;string, object&gt;();
          foreach (DataColumn col in dt.Columns)
          {
              row.Add(col.ColumnName, dr[col]);
          }
          rows.Add(row);
      }
      sqlConnection.Close();
      return serializer.Serialize(rows);
  }
  </code></pre>
  
  <p>These codes works properly. But when it comes to INSERT SQL statement, I not sure how to pass the returning boolean into JSON:</p>
  
  <pre><code>[WebMethod]
  public bool addUser(UserModel um)
  {
      bool result = false;
      result = Conversion.intToBool(SplashAwardsDB.executeNonQuery(
              "INSERT INTO dbo.User ("
              + "userName, password, firstName, lastName, address, contactNo, birthDate, familyID, familyRole, x, y ) "
              + " VALUES ("
              + "'" + um.userName + "', "
              + "'" + um.password + "', "
              + "'" + um.firstName + "', "
              + "'" + um.lastName + "', "
              + "'" + um.address + "', "
              + "'" + um.contactNo + "', "
              + "'" + um.birthDate + "', "
              + "'" + um.familyID + "', "
              + "'" + um.familyRole + "', "
              + "'" + um.x + "', "
              + "'" + um.y + "')"
              ));
          return result;
      }
  </code></pre>
  
  <p>Any guides on how to serialize it?</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>[WebMethod]
  public string checkLoginCredential(string userName, string password)
  {
      bool result = false;
      using (var connection = new SqlConnection(SplashAwardsDB.connectionString))
      {
          SqlCommand command = new SqlCommand("SELECT userName, password FROM dbo.User WHERE userName = '" + userName + "' AND password = '" + password + "'", connection);
          connection.Open();
          using (var dr = command.ExecuteReader())
          {
              if (dr.Read())
              {
                  Session["userName"] = dr["userName"];
                  result = true;
              }
          }
      }            
      return serializer.Serialize(result);
  }
  </code></pre>
  
  <p>basically I am trying to check for login credential. If the username and password match, I will store the userName into sesssion. So how should I modify this so that when my friend call this method, it will return the session data?</p>