public void Comment(string ISBN, string comm) { string isbn_10; Int64 isbn_13; Book bk = new Book(); string cs = ConfigurationManager.ConnectionStrings["DatabaseServices"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { con.Open(); if (ISBN.Length == 10) { isbn_10 = ISBN.ToString(); isbn_13 = 0; } else { isbn_13 = Int64.Parse(ISBN); isbn_10 = "0"; } string sql = "Update Book set comment=@comment where isbn_10 =@isbn_10 or isbn_13=@isbn_13"; SqlCommand cmd2 = new SqlCommand(sql, con); SqlParameter parameter = new SqlParameter(); cmd2.Parameters.Add("@isbn_10", SqlDbType.NVarChar, 10).Value = isbn_10; cmd2.Parameters.Add("@isbn_13", SqlDbType.BigInt).Value = isbn_13; cmd2.Parameters.Add("@comment", SqlDbType.NVarChar, 200).Value = comm; cmd2.CommandType = CommandType.Text; cmd2.ExecuteScalar(); JavaScriptSerializer js = new JavaScriptSerializer(); SqlDataReader rdr = cmd2.ExecuteReader(); Context.Response.Write(js.Serialize(bk)); } }
public void GetBookDetails(string ISBN) { string isbn_10; Int64 isbn_13; Book bk = new Book(); string cs = ConfigurationManager.ConnectionStrings["DatabaseServices"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { con.Open(); if (ISBN.Length == 10) { isbn_10 = ISBN.ToString(); isbn_13 = 0; } else { isbn_13 = Int64.Parse(ISBN); isbn_10 = "0"; } string sql = "Select author,title,pagecount,isbn_10,isbn_13,RDStatus,comment from Book where isbn_10 =@isbn_10 or isbn_13=@isbn_13"; SqlCommand cmd2 = new SqlCommand(sql, con); SqlParameter parameter = new SqlParameter(); cmd2.Parameters.Add("@isbn_10", SqlDbType.NVarChar, 10).Value = isbn_10; cmd2.Parameters.Add("@isbn_13", SqlDbType.BigInt).Value = isbn_13; cmd2.CommandType = CommandType.Text; cmd2.ExecuteScalar(); JavaScriptSerializer js = new JavaScriptSerializer(); SqlDataReader rdr = cmd2.ExecuteReader(); if (rdr.HasRows) { bk.source = true; bk.totalitems = 1; while (rdr.Read()) { bk.authors1 = rdr["Author"].ToString(); bk.title1 = rdr["Title"].ToString(); bk.pageCount1 = Convert.ToInt32(rdr["PageCount"]); bk.ReadStatus = rdr["RDStatus"].ToString(); bk.comment = rdr["comment"].ToString(); Context.Response.Write(js.Serialize(bk)); } } else { //IF not found in database call the GetGoogleBooks function. bk = GetGoogleBooks(ISBN); bk.source = false; Context.Response.Write(js.Serialize(bk)); } } }